从坐标获取当前地点名称(在nsstring中)
问题描述:
我有当前位置的坐标,但是如何将这些坐标转换为地名?我不想显示地图视图。由于MKReverseGeocoder在iOS 5中已弃用,有没有其他方法可以实现这一点。 在此先感谢。从坐标获取当前地点名称(在nsstring中)
答
您可以访问谷歌Places API的
http://maps.google.com/maps/geo?q=yourSearchName&output=xml
这将给有关规定,searchname细节。您可以解析xml并从该详细信息中获取经度和纬度,并可以针对这些位置进行注释。
输出也可以在json和csv中。
一些代码,可以帮助
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",coordinate]; //coordinate=-30.347744,71.3737373
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
参考谷歌APi的Here
谢谢,但有没有使用XML或JSON和CSV什么办法?仅使用iOS API。 – 2012-04-06 07:13:23
我认为,而不是MKReverseGeocoder苹果移动到CLGeocoder。尝试使用这个。 http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html#//apple_ref/occ/cl/CLGeocoder – iPrabu 2012-04-06 07:19:15
有没有任何示例代码?我已经看过CLGeocoder,但我知道如何实现它和ID我没有错,我们必须使用地图。 – 2012-04-06 07:26:29