i os developers_meetup_4_sessionon_locationservices

25
Presenta(on On GPS, Mapkit, CoreLoca(on and Region Monitoring, Geofencing

Upload: mahboob-nur

Post on 15-Jan-2015

60 views

Category:

Technology


0 download

DESCRIPTION

A Presentation on Location Services and user tracking techniques. I create the presentation for the session of iOS Developers Meetup organized by LEADS .

TRANSCRIPT

Page 1: I os developers_meetup_4_sessionon_locationservices

Presenta(on  On  

GPS,  Map-­‐kit,  Core-­‐Loca(on  and  Region  Monitoring,  Geo-­‐fencing    

Page 2: I os developers_meetup_4_sessionon_locationservices

Presented  By  

Syed  Mahboob  Nur    iOS  Developer      Blog:  hEp://mahboobiosdeveloper.blogspot.com/  Fb  Profile:  hEps://www.facebook.com/mahboob.nur      

Page 3: I os developers_meetup_4_sessionon_locationservices

GPS    The  Global  Posi(oning  System  (GPS)  is  a  satellite-­‐based  naviga(on  system  made  up  of  a  network  of  24  satellites  placed  into  orbit  by  the  U.S.    Department  of  Defense.  GPS  was  originally  intended  for  military  applica(ons,  but  in  the  1980s,  the  government  made  the  system  available  for  civilian  use.    GPS  works  in  any  weather  condi(ons,  anywhere  in  the  world,  24  hours  a  day.  There  are  no  subscrip(on  fees  or  setup  charges  to  use  GPS.  

Page 4: I os developers_meetup_4_sessionon_locationservices

Map  View  

 A  map  view  contains  a  flaEened  representa(on    of  a  spherical  object,  namely  the  Earth.    In  order  to  use  maps  effec(vely,  you  need  to    understand  a  liEle  bit  about  how  to  specify  points    in  a  map  view,  and  how  those  points  translate  to  points    on  the  Earth’s  surface.  Understanding  map  coordinate    systems  is  especially    important  if  you  plan  to  place  custom  content,  such  as  overlays  ,  on  top  of  the  map.    

Page 5: I os developers_meetup_4_sessionon_locationservices

Map  View  

Page 6: I os developers_meetup_4_sessionon_locationservices

Loca(on  Monitoring    Systems  

•  Core  Loca(on    •  Region  Monitoring  •  Geo  Fencing  •  I  Beacon    And  so  on    

Page 7: I os developers_meetup_4_sessionon_locationservices

Core  Loca(on  

•  The  Core  Loca(on  framework  lets  you  determine  the  current  loca(on  or  heading  associated  with  a  device.  The  framework  uses  the  available  hardware  to  determine  the  user’s  posi(on  and  heading.  You  use  the  classes  and  protocols  in  this  framework  to  configure  and  schedule  the  delivery  of  loca(on  and  heading  events.  You  can  also  use  it  to  define  geographic  regions  and  monitor  when  the  user  crosses  the  boundaries  of  those  regions.  In  iOS,  you  can  also  define  a  region  around  a  Bluetooth  beacon.  

Page 8: I os developers_meetup_4_sessionon_locationservices

Core  Loca(on  

Class  References   Protocol  References   Other  References  

CLBeacon  CLBeaconRegion    CLCircularRegion  CLGeocoder  CLHeading  CLLoca9on  CLLoca9onManager  CLPlacemark  CLRegion  

CLLLoca9onManagerDelegate  

Core  Loca9on  Func9ons  Core  Loca9on  Data  Types  Core  Loca9on  Constants        

Page 9: I os developers_meetup_4_sessionon_locationservices

Ini(alize  Loca(on    Manager  

-­‐  (void)startStandardUpdates  {        if  (nil  ==  loca9onManager)    

 {                loca9onManager  =  [[CLLoca9onManager  alloc]  init];  

 loca9onManager.delegate  =  self;                loca9onManager.desiredAccuracy  =  kCLLoca9onAccuracyKilometer;  

 events.  loca9onManager.distanceFilter  =  500                [loca9onManager  startUpda9ngLoca9on];  

 }  }  

Page 10: I os developers_meetup_4_sessionon_locationservices

Ac9vate  GPS  Using    CoreLoca9on  Loca9on  Manager  

 

   If(!  loca(onManager)  {    

   [loca(onManager  setDelegate:self];      [loca(onManager  startUpda(ngLoca(on];      [loca(onManager      startMonitoringSignificantLoca(onChanges];                [loca(onManager  startUpda(ngHeading];  

}  

Page 11: I os developers_meetup_4_sessionon_locationservices

Core  Loca(on    Code  

 -­‐  (void)loca9onManager:(CLLoca9onManager  *)manager  

didUpdateLoca9ons:(NSArray  *)loca9ons    {  

               NSLog(@"la9tude  %+.6f,  longitude  %+.6f\n",                loca9on.coordinate.la9tude,  loca9on.coord  inate.longitude);              }  

Page 12: I os developers_meetup_4_sessionon_locationservices

Problems  of    Ac(vate  GPS  all  the  (me  

•  Huge  BaEery  Consump(on      

Page 13: I os developers_meetup_4_sessionon_locationservices

Loca(on    Monitoring  System  that    saves  BaEery  Life  

•  Region  Monitoring  •  Geo  Fencing    

 

Page 14: I os developers_meetup_4_sessionon_locationservices

Region  Monitoring  

   Region  monitoring  lets  you  monitor  boundary  crossings  for  defined  geographical  regions  and  Bluetooth  low  energy  beacon  regions.  (iOS  4.0  and  later.)  

Page 15: I os developers_meetup_4_sessionon_locationservices

Steps  of  implemen(ng    Region  Monitoring  

•  Declare  and  Ini(alize  a  MKCoordinateRegion  •  Declare  and  Ini(alize  a  CLCircularRegion  •  Draw  a  circular  Geofence  around  the  current  loca(on  of  the  user.  

•  Start  monitoring  region  un(l  user  exit  the  region    

•  When  user  exit  the  region  draw  a  Circular  Geofence  and  start  monitoring  for  the  new  region.  

Page 16: I os developers_meetup_4_sessionon_locationservices

Important  Codes  for    implemen(ng    

Region  Monitoring  •  MKCoordinateRegion  

–  A  structure  that  defines  which  por(on  of  the  map  to  display.      MKCoordinateRegion  region;  

         region.center.la(tude  =            loca(onManager.loca(on.coordinate.la(tude;  

         region.center.longitude  =        loca(onManager.loca(on.coordinate.la(tude;  

                   region.span.la(tudeDelta  =  SPAN_VALUE;            region.span.longitudeDelta  =  SPAN_VALUE;            [self.mapView  setRegion:region  animated:YES];    

Page 17: I os developers_meetup_4_sessionon_locationservices

Important  Codes  for    implemen(ng    

Region  Monitoring  CLCircularRegion  :    The  CLCircularRegion  class  defines  the  loca(on  and  boundaries  for  a  circular  geographic  region.  You  can  use  instances  of  this  class  to  define  geo  fences  for  a  specific  loca(on.  The  crossing  of  a  geo  fence’s  boundary  causes  the  loca(on  manager  to  no(fy  its  delegate    CLCircularRegion  *myRegion=[[CLCircularRegion  alloc]initWithCenter:region.center  radius:10  iden(fier:@"myRegion"];          [loca(onManager  startMonitoringForRegion:myRegion];    

Page 18: I os developers_meetup_4_sessionon_locationservices

•  Draw  a  circular  geofence:          MKCircle  *circle  =  [MKCircle      circleWithCenterCoordinate:region.center      radius:100];    [self.mapView  addOverlay:circle];  

Important  Codes  for    implemen(ng    

Region  Monitoring  

Page 19: I os developers_meetup_4_sessionon_locationservices

•  Delegate  method  to  make  Circular  Overlay  Colorful          -­‐(MKOverlayView  *)  mapView:(MKMapView  *)mapView      viewForOverlay:(id<MKOverlay>)overlay    {            MKCircleView  *circleView  =  [[MKCircleView  alloc]      initWithCircle:overlay];            circleView.fillColor  =  [[UIColor  redColor]          colorWithAlphaComponent:0.1];            circleView.strokeColor  =  [[UIColor  blueColor]      colorWithAlphaComponent:1.0];            circleView.lineWidth  =  1;            return  circleView;    }  

 

Important  Codes  for    implemen(ng    

Region  Monitoring  

Page 20: I os developers_meetup_4_sessionon_locationservices

•  Determine  when  user  enters  and  exits  region    

 -­‐  (void)loca9onManager:(CLLoca9onManager  *)manager  didEnterRegion:(CLRegion  *)region    {  

           UIAlertView  *alert  =  [[UIAlertView  alloc]initWithTitle:@""  message:@"didEnterRegion"  delegate:nil  cancelBubonTitle:@"OK"  otherBubonTitles:nil,  nil];              [alert  show];              NSLog(@"didEnterRegion");  

 }  

 -­‐  (void)loca9onManager:(CLLoca9onManager  *)manager  didExitRegion:(CLRegion  *)region    {  

           UIAlertView  *alert  =  [[UIAlertView  alloc]initWithTitle:@""  message:@"didExitRegion"  delegate:nil  cancelBubonTitle:@"OK"  otherBubonTitles:nil,  nil];              [alert  show];    

 }  

Important  Codes  for    implemen(ng    

Region  Monitoring  

Page 21: I os developers_meetup_4_sessionon_locationservices

•  A  geo-­‐fence  is  a  virtual  perimeter  for  a  real-­‐world  geographic  areas.  

 •  A  geo-­‐fence  could  be  dynamically  generated—as  in  a  radius  around  a  store  or  point  loca(on.  Or  a  geo-­‐fence  can  be  a  predefined  set  of  boundaries,  like  school  aEendance  zones  or  neighborhood  boundaries.  Custom-­‐digi(zed  geofences  are  also  in  use.  

   

Geofencing    

Page 22: I os developers_meetup_4_sessionon_locationservices

Geofecing  

Page 23: I os developers_meetup_4_sessionon_locationservices

•  iBeacon   is   an   indoor   posi(oning   system   that  Apple   Inc   calls   "a   new   class   of   low-­‐powered,  low-­‐cost   transmiEers   that   can   no(fy   nearby  iOS  7  devices  of  their  presence.    

•  They   can   also   be   used   by   the   Android  opera(ng  system.[  The  technology  enables  an  iOS   device   or   other   hardware   to   send   push  no(fica(ons  to  iOS  devices  in  close  proximity.  

iBeacon  

Page 24: I os developers_meetup_4_sessionon_locationservices

I  Beacon  

Page 25: I os developers_meetup_4_sessionon_locationservices

 That’s  all  for  Today