实现CLLocationManagerDelegate代理
///初始化CLocationManager
- (void) initLocation
{
if([CLLocationManagerlocationServicesEnabled])
{
self.locationManager = [[CLLocationManageralloc]init];
self.locationManager.delegate =self;
self.locationManager.desiredAccuracy =kCLLocationAccuracyNearestTenMeters;
self.locationManager.distanceFilter =5.0;
}
[self.locationManagerstartUpdatingLocation];
}
-(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
{
[manager stopUpdatingLocation];
CLLocation *newLocation = locations[0];
CLGeocoder *geoCoder = [[CLGeocoderalloc]init];
[geoCoder reverseGeocodeLocation:newLocationcompletionHandler:^(NSArray *placemarks,NSError *error)
{
for (CLPlacemark *placemarkin placemarks)
{
NSString *city = placemark.administrativeArea;
XLOG(@"----%@",city);
// kde
[mUserDefaults setValue:city forKey:kCity];
}
}];
}
}
PS: IOS的自带定位获得的经纬度不是火星坐标,建议使用高德的。