鉴于目前的MapKit未提供正向地理编码功能,请问有人可以帮忙解决如何使用搜索栏来返回用户输入地址的纬度和经度坐标吗?如果有人能提供示例代码,那就太好了。
鉴于目前的MapKit未提供正向地理编码功能,请问有人可以帮忙解决如何使用搜索栏来返回用户输入地址的纬度和经度坐标吗?如果有人能提供示例代码,那就太好了。
我已经为Google的地理编码服务器创建了一个正向地理编码API。请查看我的博客文章:http://blog.sallarp.com/ipad-iphone-forward-geocoding-api-google/
我创建了SVGeocoder,这是一个简单的iOS正、反地理编码类。它也使用了Google Geocoding API,并返回一个MKPlacemark对象。
以下是如何对地址字符串进行地理编码:
NSString *addressString = @"3245 St-Denis, Montreal"
SVGeocoder *geocodeRequest = [[SVGeocoder alloc] initWithAddress:addressString];
[geocodeRequest setDelegate:self];
[geocodeRequest startAsynchronous];
你可以这样对一个CLLocationCoordinate2D对象进行反向地理编码:
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(45.54181, -73.62928);
SVGeocoder *rGeocoderRequest = [[SVGeocoder alloc] initWithCoordinate:coordinate];
[rGeocoderRequest setDelegate:self];
[rGeocoderRequest startAsynchronous];
SVGeocoderDelegate提供了这两个方法:
- (void)geocoder:(SVGeocoder *)geocoder didFindPlacemark:(MKPlacemark *)placemark;
- (void)geocoder:(SVGeocoder *)geocoder didFailWithError:(NSError *)error;
我在 GitHub 上使用 iOS5 CoreLocation 框架中的 CLGeocoder 进行了一些关于正向和反向地理编码的小工作,希望对你有所帮助。
https://github.com/Mangesh20/geocoding这里还有一个框架:https://github.com/tylerhall/CoreGeoLocation
来自文档的评论: 一个基于Objective-C的地理编码器和反向地理编码器,主要包装了Yahoo的地理编码服务或Google的Geo APIs。
在MapKit中没有这样的功能。你最好的选择是调用第三方网络服务。谷歌有一些API可以实现这个功能,雅虎也有类似的服务。但两者都有商业使用限制,所以请仔细阅读协议。