- (AMapLocationManager *)locationManager
{
if (_locationManager == nil) {
[AMapServices sharedServices].apiKey = MAPKEY;
_locationManager = [[AMapLocationManager alloc] init];
//设置期望定位精度
[_locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
//设置不允许系统暂停定位
[_locationManager setPausesLocationUpdatesAutomatically:NO];
//设置允许在后台定位
[_locationManager setAllowsBackgroundLocationUpdates:YES];
//设置定位超时时间
[_locationManager setLocationTimeout:DefaultLocationTimeout];
//设置逆地理超时时间
[_locationManager setReGeocodeTimeout:DefaultReGeocodeTimeout];
[_locationManager setDelegate:self];
/*
设置多大距离返回位置信息,这里我设置的是100,
当用户位置移动超过100米就给我返回位置信息,
我就可以上传位置信息或者做其他处理
*/
_locationManager.distanceFilter = 100;
}
return _locationManager;
}
#pragma mark --------- AMapLocationManagerDelegate
- (void)amapLocationManager:(AMapLocationManager *)manager didUpdateLocation:(CLLocation *)location reGeocode:(AMapLocationReGeocode *)reGeocode
{
NSLog(@"location:{lat:%f; lon:%f; accuracy:%f}", location.coordinate.latitude, location.coordinate.longitude, location.horizontalAccuracy);
// 根据设置Manager的信息用户位置移动100米进入该代理回调。
}
// 进入后台
- (void)applicationDidEnterBackground:(UIApplication *)application {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
// 从前台进入后台
/*
注意:在你调用下边方法后就开启连续定位
你的单次定位就会被关闭 信息就会被覆盖
所以要明确自己的需求哦
*/
[self.locationManager startUpdatingLocation];// 开启定位
}
// 从后台进入前台
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self.locationManager stopUpdatingLocation];// 结束定位
}