CLLocationManager获取所在城市

CLLocationManager获取所在城市

- (void)locationManager:(CLLocationManager *)manager 
    didUpdateToLocation:(CLLocation *)newLocation 
           fromLocation:(CLLocation *)oldLocation {
//获取所在地城市名
    CLGeocoder *geocoder=[[CLGeocoder alloc]init];
    [geocoder reverseGeocodeLocation:newLocation completionHandler:^(NSArray *placemarks,NSError *error)
     {
         for(CLPlacemark *placemark in placemarks)
         {
             self.currentCity=[[placemark.addressDictionary objectForKey:@"City"] substringToIndex:2];
             NSLog(@"str%@",currentCity);
         }
     }];
    [self.locationManager stopUpdatingLocation];
}

你可能感兴趣的:(location)