【问题标题】:iOS location from lat and long经纬度的 iOS 位置
【发布时间】:2012-09-26 03:27:19
【问题描述】:

我是 iOS 开发的新手。我有纬度和经度的值。我想使用纬度和经度来获取位置的名称?在iOS中是否可以。

【问题讨论】:

    标签: objective-c ios location latitude-longitude


    【解决方案1】:

    是的,它可能称为reverse geocoding。您需要先导入CoreLocation 框架,然后在iOS5(及更高版本)中使用CLGeocoder。对于 iOS4 及以下其mkreversegeocoder。以下是使用 `CLGeocoder 获取地址的方法,只需将位置对象提供给它,剩下的就交给它了。

    [self.geoCoder reverseGeocodeLocation: locationManager.location completionHandler: 
         ^(NSArray *placemarks, NSError *error) {
    
             //Get nearby address
             CLPlacemark *placemark = [placemarks objectAtIndex:0];
    
             //String to hold address
             NSString *locatedAt = [[placemark.addressDictionary valueForKey:@"FormattedAddressLines"] componentsJoinedByString:@", "];
    
             //Print the location to console
             NSLog(@"I am currently at %@",locatedAt);
    
         }];
    

    您获得的placemarks 数组是CLPlacemark 对象的实例。 IT 让您可以访问 -

    Accessing the Placemark Attributes
      name  property
      addressDictionary  property
      ISOcountryCode  property
      country  property
      postalCode  property
      administrativeArea  property
      subAdministrativeArea  property
      locality  property
      subLocality  property
      thoroughfare  property
      subThoroughfare  property
      region  property
    

    【讨论】:

      【解决方案2】:

      另一种简单的方法是使用谷歌地图rest api,对以下网址进行网络服务调用,它将返回一个包含位置详细信息的json

      http://maps.googleapis.com/maps/api/geocode/json?latlng=10.03,10.03&sensor=false

      【讨论】:

        【解决方案3】:

        是的。对于 iOS5 及更高版本,您可以使用 CLGeocoder

        如果你必须支持以前的操作系统版本,你可以使用MKReverseGeocoder

        【讨论】:

        • mkreversegeocoder 是旧的不推荐使用的 api。你应该使用CLGeocoder,请在有人反对之前更正你的答案
        【解决方案4】:

        除了MKReverseGeocoder,我推荐你使用google api。我在我的应用程序中使用它,没有崩溃和快速响应。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-05-14
          • 2017-11-10
          • 1970-01-01
          • 1970-01-01
          • 2012-11-08
          相关资源
          最近更新 更多