首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Iphone >

用CLLocationManager得到当前城市和国家的名称。该怎么处理

2013-10-21 
用CLLocationManager得到当前城市和国家的名称。原问题来自于CSDN问答频道,详细解决方案见:http://ask.csdn

用CLLocationManager得到当前城市和国家的名称。
原问题来自于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);
             }
         }];
    }
}


[解决办法]
哈哈哈哈~~~
[解决办法]
好分享,好分享!!!我晕,为什么非要6个字!!!
[解决办法]
用CLLocationManager得到当前城市和国家的名称。该怎么处理
[解决办法]
多谢分享!哈哈~
[解决办法]
这个办法很好,得顶一下
[img=http://219.157.112.197/iRadio_vote.asp?VoTeid=182][/img]
[解决办法]
不太懂,顶一个
[解决办法]
顶一个顶一个~
[解决办法]
积分怎么还没有呢?
[解决办法]
貌似不错 看不懂 但是很厉害的样子
[解决办法]
用CLLocationManager得到当前城市和国家的名称。该怎么处理
 看不懂 但是很厉害的样子 
[解决办法]
买噶的···好家伙
[解决办法]
好分享,好分享!!!我晕,为什么非要6个字!!!
[解决办法]
用CLLocationManager得到当前城市和国家的名称。该怎么处理学习了
[解决办法]
多谢 多谢 有用
[解决办法]
谢谢提供!谢谢分享!
[解决办法]
感谢分享!多谢多谢!
[解决办法]
这个程式看起来对我比较难
[解决办法]
IOS6以后,苹果地图reverseGeocodeLocation 解析效果极差,50%以上城市名称都找不到,请问还有何好方法获取所在城市名?


怀念谷歌地图时代。。。

热点排行