Quick Start: Location Service

Quick Start: Location Service

The integration principle is the same accross all SDK services, so only the integration of the Location Service is detailed hereafter.
Please refer to the API Reference Guide for details about other services.

Initialize Location Service

  • Import the following headers into your source file:
#import "NAOLocationHandle.h"
#import "NAOLocationHandleDelegate.h"
#import "NAOSyncDelegate.h"
#import "NAOSensorsDelegate.h"
#import "DBNAOERRORCODE.h"
#import "DBTNAOFIXSTATUS.h"
  • Get an API Key on NAO Cloud (that key is created when you create a site on NAO Cloud).
    If a site is used in several applications, you can also create a new API key for the same site in NAO Cloud Developer section.
  • implement the NAOSyncDelegateNAOLocationHandleDelegateNAOSensorsDelegate protocols on any object of your choosing (e.g. a UIViewController), You will then be able to receive the NAO engine callbacks.
  • You may also declare a NAOLocationHandle member (or property) as you will need this to interact with the Location service.
@interface MyCustomViewController : UIViewController <NAOSyncDelegate, NAOLocationHandleDelegate, NAOSensorsDelegate> {
    NAOLocationHandle * mLocationHandle;
}
@end
  • Initialize your NAOLocationHandle object, configure it with your API key and your delegates:
mLocationHandle = [[NAOLocationHandle alloc] initWithKey:@"YOUR_API_KEY" 
                                             delegate:/* your (id<NAOLocationHandleDelegate>) */
                                             sensorsDelegate:/* your (id<NAOSensorsDelegate>) */];
  • No matter your use case, and the location-related authorization your app has (While using, Always, …), the initialization should only be performed once during the lifetime of the app.
  • Call synchronizeData to retrieve the positioning database (PDB) available on NAO Cloud:

[mlocationHandle synchronizeData:/* your (id<NAOSyncDelegate>) */];
[mlocationHandle start];

The recommended call flow is to first call synchronizeData(), then the Services start() method. The NAO SDK will internally detect that a synchronization is ongoing, and update everything automatically. In the event that the synchronization would not go through, but a previous was already downloaded/embedded, the NAO SDK would still be able to run.

  • Implement the synchronization callbacks, the location will automatically start using these files when the sync succeeds
- (void)didSynchronizationSuccess {
    // sync OK ! The new files will be taken into account automatically by the NAO SDK, no need to restart it.
}

- (void)didSynchronizationFailure:(DBNAOERRORCODE)errorCode msg:(NSString*) message {
    // synchronization failed, check error code and message !
}
  • You need to stop your NAOLocationHandle when you don’t need it anymore (it will be stopped if there’s no delegate).
[mlocationHandle stop];

Request sensor activation

  • The user may not have its phone’s sensors activated.
    In that case, the engine will trigger some callbacks that you can use to ask the user for sensor activation:
- (void) requiresWifiOn {
   // warn the user (ie. with an UIAlertController)
}
- (void) requiresBLEOn {
    // warn the user (ie. with an UIAlertController)
}
- (void) requiresLocationOn {
    // warn the user (ie. with an UIAlertController)
}
- (void) requiresCompassCalibration {
    // warn the user (ie. with an UIAlertController)
}

Get The User Location

  • In standard mode, a user location will be sent every second by this method.
- (void) didLocationChange:(CLLocation *) location {
    // a new location has been received !
    // you can display the user location to your map here
}

The location given by the NAOLocationHandle is in a WGS84 format (like GPS) and it is encapsulated into a standard CLLocation object.

The following fields are used:

  • coordinate
    • Latitude/Longitude
  • altitude
  • course
    • Heading (degrees)
  • timestamp
  • horizontalAccuracy
    • Confidence circle
  • verticalAccuracy
    • 0: BLE based location
    • -500: GPS based location, projected on graph (outdoor location)
    • -1000: raw GPS location (out of graph, outdoor location)
  • The following method will let you know when the NAOLocationHandle status changes. For more information about the status please refer to the API Reference Guide).
- (void) didLocationStatusChanged:(DBTNAOFIXSTATUS)status {
}
  • If an error occurs, that callback is triggered:
- (void) didFailWithErrorCode:(DBNAOERRORCODE)errCode andMessage:(NSString *)message {
    NSLog(@"Location Error: %@", message);
}
    • Related Articles

    • Restart the location service

      Overview NAOLocationHandle class provides the restart method that stops and stars the location service and therefore re-initializes the environment and variables are being used. However, we strongly recommend that you avoid calling this method ...
    • Restart the location service

      Overview NAOLocationHandle class provides the restart method that stops and stars the location service and therefore re-initializes the environment and variables are being used. However, we strongly recommend that you avoid calling this method ...
    • Tracking Service

      This is a new service included in version 4.10.0. Tracking service allows once activated to track the position of people in a building. Warning: this service must be activated with the user’s consent. otherwise this service will not be started Setup ...
    • Service Selection

      Whatever the services you are using, there are two mandatory delegates that your app must implement, since they’re used by all the services. Data Synchronisation Delegate (NAOSyncDelegate): Gives you the result of the data synchronisation requested ...
    • Get last known location

      GetLastKnownLocation Overview GetLastKownLocation API provides the last known location. On Android, the method returns a Location object. However, it requires at least one running service otherwise it will return a null object. Example On Android ...