【问题标题】:how to find addressfrom latitude and longitude in IOS?如何在IOS中从经纬度查找地址?
【发布时间】:2014-04-03 07:21:22
【问题描述】:
【问题讨论】:
标签:
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);
}
}];
}
【解决方案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)
})