【问题标题】:how to find addressfrom latitude and longitude in IOS?如何在IOS中从经纬度查找地址?
【发布时间】:2014-04-03 07:21:22
【问题描述】:

我正在尝试获取地址(仅最近的街道、地标或特征以及最近的城市、村庄或城镇)。我试过 http://maps.googleapis.com/maps/api/geocode/json?latlng=44.4647452,7.3553838&sensor=true http://nominatim.openstreetmap.org/reverse?format=json&lat=44.4647452&lon=7.3553838&zoom=18&addressdetails=1 但是在 google api 中它返回了这么多 json 对象并且非常混乱,并且在 nominatim 的 api 中有时它不会返回任何结果或错过一些字段,简而言之它不会返回精确的结果。任何人都可以建议我任何其他 api 或任何参考吗?

【问题讨论】:

  • 您正在搜索什么样的地方,例如:餐厅、俱乐部...
  • 我想通过经纬度获取街道名称和城市名称

标签: ios latitude-longitude street-address


【解决方案1】:
-(void)getAddressFromCurruntLocation:(CLLocation *)location{

    CLGeocoder *geocoder = [[CLGeocoder alloc] init];
   [geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error)
   {
     if(placemarks && placemarks.count > 0)
     {
         CLPlacemark *placemark= [placemarks objectAtIndex:0];
         //address is NSString variable that declare in .h file.
         address = [[NSString stringWithFormat:@"%@ , %@ , %@",[placemark thoroughfare],[placemark locality],[placemark administrativeArea]] retain];
         NSLog(@"New Address Is:%@",address);
     }
 }];
}

【讨论】:

    【解决方案2】:

    你可以试试这个方法:

    CLGeocoder *geocoder = [CLGeocoder alloc]init];     
    [geocoder reverseGeocodeLocation:location completionHandler:
                ^(NSArray* placemarks, NSError* error){}];
    

    https://developer.apple.com/library/ios/documentation/userexperience/conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html#//apple_ref/doc/uid/TP40009497-CH4-SW1

    【讨论】:

      【解决方案3】:

      你会在谷歌地图文档中得到答案,所以去想吧

      https://developers.google.com/maps/documentation/geocoding/?csw=1#JSON

      【讨论】:

        【解决方案4】:

        我为 OpenStreetMap 的 Nominatim 构建了一个 Swift 3 包装器。在这里查看:https://github.com/caloon/NominatimSwift

        NominatimSwift 使用免费的 Nominatim API 对 OpenStreetMap 数据进行地理编码。您还可以搜索地标。它需要网络连接。

        地理编码地址和地标:

        Nominatim.getLocation(fromAddress: "The Royal Palace of Stockholm", completion: {(error, location) -> Void in
          print("Geolocation of the Royal Palace of Stockholm:")
          print("lat = " + (location?.latitude)! + "   lon = " + (location?.longitude)!)
        })
        

        反向地理编码:

        Nominatim.getLocation(fromLatitude: "55.6867243", longitude: "12.5700724", completion: {(error, location) -> Void in
          print("City for geolocation 55.6867243/12.5700724:")
          print(location?.city)
        })
        

        【讨论】:

          猜你喜欢
          • 2012-03-16
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-04-04
          • 1970-01-01
          • 1970-01-01
          • 2021-06-11
          相关资源
          最近更新 更多