用CLLocationManager得到当前城市和国家的名称。

iOS 码拜 8年前 (2015-11-15) 744次浏览
原问题来自于CSDN问答频道,详细解决方案见:http://ask.csdn.net/questions/1706
问题描述:
通过使用CLLocationManager得到当前城市和国家的名称。
解决方案:

- (void) getReverseGeocode
{
    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
    if(currentLatLong.count > 0)
    {
        CLLocationCoordinate2D myCoOrdinate;
        myCoOrdinate.latitude = LatValue;
        myCoOrdinate.longitude = LangValue;
        CLLocation *location = [[CLLocation alloc] initWithLatitude:myCoOrdinate.latitude longitude:myCoOrdinate.longitude];
        [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
         {
             if (error)
             {
                 NSLog(@"failed with error: %@", error);
                 return;
             }
             if(placemarks.count > 0)
             {
                 NSString *MyAddress = @"";
                 NSString *city = @"";
                 if([placemark.addressDictionary objectForKey:@"FormattedAddressLines"] != NULL)
                     MyAddress = [[placemark.addressDictionary objectForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
                 else
                     MyAddress = @"Address Not founded";
                 if([placemark.addressDictionary objectForKey:@"SubAdministrativeArea"] != NULL)
                     city = [placemark.addressDictionary objectForKey:@"SubAdministrativeArea"];
                 else if([placemark.addressDictionary objectForKey:@"City"] != NULL)
                     city = [placemark.addressDictionary objectForKey:@"City"];
                 else if([placemark.addressDictionary objectForKey:@"Country"] != NULL)
                     city = [placemark.addressDictionary objectForKey:@"Country"];
                 else
                     city = @"City Not founded";
               NSLog(@"%@",city);
               NSLog(@"%@", MyAddress);
             }
         }];
    }
}
解决方案:4分
好帖,mark
解决方案:4分
哟谢谢拉  顶顶
解决方案:4分
看不太懂,顶起!
解决方案:4分
买噶的···好家伙
解决方案:4分
解决方案:4分
哈哈哈哈~~~
解决方案:4分
好分享,好分享!本人晕,为什么非要6个字!
解决方案:4分
解决方案:4分
多谢分享!哈哈~
解决方案:4分
这个办法很好,得顶一下
[img=http://219.157.112.197/iRadio_vote.asp?VoTeid=182][/img]
解决方案:4分
不太懂,顶一个
解决方案:4分
顶一个顶一个~
解决方案:4分
积分怎么还没有呢?
解决方案:4分
貌似不错 看不懂 但是很厉害的样子
解决方案:4分
看不懂 但是很厉害的样子
解决方案:4分
买噶的···好家伙
解决方案:4分
好分享,好分享!本人晕,为什么非要6个字!
解决方案:4分
学习了
解决方案:4分
多谢 多谢 有用
解决方案:4分
谢谢提供!谢谢分享!
解决方案:4分
感谢分享!多谢多谢!
解决方案:4分
这个程式看起来对本人比较难
解决方案:12分
IOS6以后,苹果地图reverseGeocodeLocation 解析效果极差,50%以上城市名称都找不到,问一下还有何好方法获取所在城市名?
怀念谷歌地图时代。

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明用CLLocationManager得到当前城市和国家的名称。
喜欢 (0)
[1034331897@qq.com]
分享 (0)