- (AMapLocationManager *)locationManager
{
if (_locationManager == nil) {
[AMapServices sharedServices].apiKey = MAPKEY;
_locationManager = [[AMapLocationManager alloc] init];
//設置期望定位精度
[_locationManager setDesiredAccuracy:kCLLocationAccuracyHundredMeters];
//設置不允許系統(tǒng)暫停定位
[_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);
// 根據(jù)設置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.
// 從前臺進入后臺
/*
注意:在你調用下邊方法后就開啟連續(xù)定位
你的單次定位就會被關閉 信息就會被覆蓋
所以要明確自己的需求哦
*/
[self.locationManager startUpdatingLocation];// 開啟定位
}
// 從后臺進入前臺
- (void)applicationDidBecomeActive:(UIApplication *)application {
[self.locationManager stopUpdatingLocation];// 結束定位
}