i os developers_meetup_4_sessionon_locationservices
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
Presenta(on On
GPS, Map-‐kit, Core-‐Loca(on and Region Monitoring, Geo-‐fencing
Presented By
Syed Mahboob Nur iOS Developer Blog: hEp://mahboobiosdeveloper.blogspot.com/ Fb Profile: hEps://www.facebook.com/mahboob.nur
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.
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.
Map View
Loca(on Monitoring Systems
• Core Loca(on • Region Monitoring • Geo Fencing • I Beacon And so on
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.
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
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];
} }
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];
}
Core Loca(on Code
-‐ (void)loca9onManager:(CLLoca9onManager *)manager
didUpdateLoca9ons:(NSArray *)loca9ons {
NSLog(@"la9tude %+.6f, longitude %+.6f\n", loca9on.coordinate.la9tude, loca9on.coord inate.longitude); }
Problems of Ac(vate GPS all the (me
• Huge BaEery Consump(on
Loca(on Monitoring System that saves BaEery Life
• Region Monitoring • Geo Fencing
Region Monitoring
Region monitoring lets you monitor boundary crossings for defined geographical regions and Bluetooth low energy beacon regions. (iOS 4.0 and later.)
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.
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];
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];
• Draw a circular geofence: MKCircle *circle = [MKCircle circleWithCenterCoordinate:region.center radius:100]; [self.mapView addOverlay:circle];
Important Codes for implemen(ng
Region Monitoring
• 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
• 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
• 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
Geofecing
• 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
I Beacon
That’s all for Today