在 iOS 5 中,有一种转发地理编码地址的新方法(将 1 Infinite Loop, CA, USA 等地址转换为 lat/lang 地址)。有关此的更多信息请参见此处。 http://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/LocationAwarenessPG/UsingGeocoders/UsingGeocoders.html#//apple_ref/doc/uid/TP40009497-CH4-SW1
有人尝试将前向地理编码 CLPlacemark 对象放在 MKMapView 上吗?我在地理编码后有一个 CLPlacemark 对象,但不知道如何将其放在地图上。
我将不胜感激任何类型的帮助。谷歌到目前为止没有任何帮助。
除了选择答案之外,还有这种方法可以向mapView添加注释以进行正向地理编码。
CLPlacemark 对象可以直接转换为 MKPlacemark 并添加到地图视图中。
像这样:
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:placemark];
[self.mapView addAnnotation:placemark];
这是正向地理编码的完整示例。
NSString *address = @"1 Infinite Loop, CA, USA";
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:address
completionHandler:^(NSArray* placemarks, NSError* error){
// Check for returned placemarks
if (placemarks && placemarks.count > 0) {
CLPlacemark *topResult = [placemarks objectAtIndex:0];
// Create a MLPlacemark and add it to the map view
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:topResult];
[self.mapView addAnnotation:placemark];
[placemark release];
}
[geocoder release];
}];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)