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];
}

posted @ 2012-07-17 10:16  GreyWolf  阅读(713)  评论(0编辑  收藏  举报