Location Updates and Callbacks
The Navigation SDK depends heavily on location services. When you initialize AMapNaviDriveManager, the SDK automatically calls the system location manager (CLLocationManager) internally. If your app requires background navigation, pay attention to the following two properties on AMapNaviBaseManager:
/// Specifies whether location updates can be paused automatically by the system. Defaults to YES.
@property(nonatomic, assign) BOOL pausesLocationUpdatesAutomatically;
/// Specifies whether background location updates are allowed. Defaults to NO (iOS 9.0 and later only).
/// Note: When set to YES, the "Location updates" capability under Background Modes must be enabled,
/// otherwise an exception will be thrown.
@property (nonatomic, assign) BOOL allowsBackgroundLocationUpdates;You must configure these properties as follows:
[[AMapNaviDriveManager sharedInstance] setPausesLocationUpdatesAutomatically:NO];
[[AMapNaviDriveManager sharedInstance] setAllowsBackgroundLocationUpdates:YES];Vehicle Location Data
The vehicle location information for driving navigation is returned through the <AMapNaviDriveDataRepresentable> protocol callback. The location data is encapsulated in the AMapNaviLocation class:
/// The current vehicle location
@interface AMapNaviLocation : NSObject<NSCopying>
/// Latitude and longitude
@property (nonatomic, strong) AMapNaviPoint *coordinate;
/// Accuracy
@property (nonatomic, assign) double accuracy;
/// Altitude
@property (nonatomic, assign) double altitude;
/// Heading
@property (nonatomic, assign) double heading;
/// Speed (km/h)
@property (nonatomic, assign) NSInteger speed;
/// Timestamp
@property (nonatomic, strong) NSDate *timestamp;
/// Whether the location is matched to a road
@property (nonatomic, assign) BOOL isMatchNaviPath;
/// The index of the current segment, starting from 0 (since 6.7.0)
@property (nonatomic, assign) int currentSegmentIndex;
/// The index of the current link, starting from 0 (since 6.7.0)
@property (nonatomic, assign) int currentLinkIndex;
/// The index of the current point on the current link, starting from 0 (since 6.7.0)
@property (nonatomic, assign) int currentPointIndex;
/// Whether the current location is a network point used for navigation.
/// Note: This applies only to driving navigation. (since 6.8.0)
@property (nonatomic, assign) BOOL isNetworkNavi;
@endLocation Update Callback
/**
* @brief Vehicle location update callback (since 5.0.0)
* This callback is triggered for both simulated and real-time navigation.
* @param driveManager The driving navigation manager
* @param naviLocation Vehicle location information, see AMapNaviLocation class
*/
- (void)driveManager:(AMapNaviDriveManager *)driveManager updateNaviLocation:(nullable AMapNaviLocation *)naviLocation;