iOS 地理位置反编码

获取城市的名字,具体还可以获得街道信息,不多说直接上代码:

 

CLLocation *currentLocation = [locations lastObject];

    MJLog(@"currentLocation == %@",currentLocation);

         // 创建位置

         CLGeocoder *revGeo = [[CLGeocoder alloc] init];

        [revGeo reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemarks, NSError *error) {

         

        // 地理位置反编

         if (!error && [placemarks count] > 0) {

         NSDictionary *dict = [[placemarks objectAtIndex:0] addressDictionary];

         _currentPosition = [dict objectForKey:@"City"];

         MJLog(@"City address: %@",_currentPosition); }

         else  {

         Alert(@"温馨提示", @"获取位置失败");

         MJLog(@"ERROR: %@", error); }

         }];

posted on 2015-07-27 16:13  哈利波特大  阅读(303)  评论(0编辑  收藏  举报