core location

LOCATION TECHNOLOGIES


  • cellular positioning
  • wi-fi positioning
  • Global Navigation Satellite System

User's Location



  • StandardLocation Service
  • Significant-Change Location Service

Standard Location Service


  • Configurable general purpose solution for getting location data.
  • Create an instance of CLLocationManager class
  • Configure its desired accuracy/distance filter properties.
  • Assign delegate to the object and call startUpdatingLocation.
  • To stop the delivery of location update call stopUpdatingLocation.

Starting standard location service


 - (void)startStandardUpdates
{
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
 
    locationManager.delegate = self;
    locationManager.desiredAccuracy = kCLLocationAccuracyKilometer;
 
    // Set a movement threshold for new events.
    locationManager.distanceFilter = 500; // meters
 
    [locationManager startUpdatingLocation];
}

significant-change location service


  • Represents a power-saving alternative to the standard location service.
  • Also wake up an iOS app that is currently suspended or not running in order to deliver new location data.
  • Create an instance of CLLocationManager class
  • Assign delegate to the object and call startMonitoringSignificantLocationChanges.

SIGNIFICANT-CHANGE LOCATION SERVICE


 - (void)startSignificantChangeUpdates
{
    // Create the location manager if this object does not
    // already have one.
    if (nil == locationManager)
        locationManager = [[CLLocationManager alloc] init];
 
    locationManager.delegate = self;
    [locationManager startMonitoringSignificantLocationChanges];
}

Receiving Location Data from a Service


  • Way of receiving event is same.
  • Processing an incoming location event
  •  // Delegate method from the CLLocationManagerDelegate protocol.
    - (void)locationManager:(CLLocationManager *)manager
          didUpdateLocations:(NSArray *)locations {
        // If it's a relatively recent event, turn off updates to save power.
       CLLocation* location = [locations lastObject];
       NSDate* eventDate = location.timestamp;
       NSTimeInterval howRecent = [eventDate timeIntervalSinceNow];
       if (abs(howRecent) < 15.0) {
          // If the event is recent, do something with it.
          NSLog(@"latitude %+.6f, longitude %+.6f\n",
                  location.coordinate.latitude,
                  location.coordinate.longitude);
       }
    }

Region Monitoring and iBeacon



The Core Location framework provides two ways to detect a user’s entry and exit into specific regions.

  • A geographical region
  • a beacon region

geographical region

A geographical region is an area defined by a circle of a specified radius around a known point on the Earth’s surface.

  • Define geographical regions using the CLCircularRegion class.
  • Region must include both the data that defines the desired geographic area and a unique identifier string.
  • To register a region, call the startMonitoringForRegion
  • Only boundary crossings generate an event.

GEOGRAPHICAL REGION

 // Create the geographic region to be monitored.
CLCircularRegion *geoRegion = [[CLCircularRegion alloc] initWithCenter:overlay.coordinate radius:radius identifier:identifier]; [self.locManager startMonitoringForRegion:geoRegion];
  • Handling Boundary-Crossing

 locationManager:didEnterRegion: locationManager:didExitRegion:

Beacon Region

  • A beacon region is an area defined by the device’s proximity to Bluetooth low-energy beacons.
  • devices that advertise a particular Bluetooth low-energy payload.
  • core bluetooth framework.
  • Bluetooth low-energy beacons that advertise a combination of the following values:
  •       
  • A proximity UUID ($ uuidgen)
  • A major value (optional)
  • A minor value (optional)

create a beacon region


 // Create a NSUUID object
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A77A1B68-49A7-4DBF-914C-760D07FBB87B"];
    
    // Initialize the Beacon Region
    self.myBeaconRegion = [[CLBeaconRegion alloc]           initWithProximityUUID:uuid                                                                  major:1                                                                  minor:1                                                             identifier:@"com.appcoda.testregion"];

advertise your beacon’s proximity UUID


  • CBPeripheralManager class
  • In Core Bluetooth, a peripheral is a device that advertises and shares data using Bluetooth low energy.
  •  // Create the peripheral manager.   CBPeripheralManager *peripheralManager = [[CBPeripheralManager alloc]
          initWithDelegate:selfqueue:nil options:nil];
     
       // Start advertising your beacon's data.
       [peripheralManager startAdvertising:beaconPeripheralData];

Receiving Becons


  self.locationManager = [[CLLocationManager alloc] init];    self.locationManager.delegate = self;
    
    // Create a NSUUID with the same UUID as the broadcasting beacon
    NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:@"A77A1B68-49A7-4DBF-914C-760D07FBB87B"];
    
    // Setup a new region with that UUID and same identifier as the broadcasting beacon
    self.myBeaconRegion = [[CLBeaconRegion alloc] initWithProximityUUID:uuid
                                                             identifier:@"com.appcoda.testregion"];
    
    // Tell location manager to start monitoring for the beacon region
    [self.locationManager startMonitoringForRegion:self.myBeaconRegion];

Thank  U

core location

By Torry Harris Business Solutions