问题描述
在iOS 5中,有一种转发地理编码地址的新方法(将地址转换为1 Infinite Loop,CA,USA转换为lat / lang地址)。
In iOS 5, there is a new way to forward geocode address (converting address like 1 Infinite Loop, CA, USA to lat/lang address). More info on this is here.
是否有人试图将前向地理编码的CLPlacemark对象放在MKMapView上?我在地理编码后有一个CLPlacemark对象,但不知道如何将它放在地图上。
Has anybody tried to put the forward geocoded CLPlacemark object on a MKMapView? I have a CLPlacemark object after geocoding but have no clue how to put it on a map.
我会很感激任何类型的帮助。谷歌到目前为止没有任何帮助。
I would appreciate any type of help. Google is of no help so far.
推荐答案
除了选定的答案,还有这种方法可以添加注释到mapView用于转发地理编码。
CLPlacemark对象可以直接转换为MKPlacemark并添加到mapview。
喜欢这个:
In addition to the selected answer, there is also this way for adding annotations to the mapView for forward geocoding.The CLPlacemark object can be directly cast to MKPlacemark and added to the mapview.Like this:
MKPlacemark *placemark = [[MKPlacemark alloc] initWithPlacemark:placemark];
[self.mapView addAnnotation:placemark];
以下是转发地理编码的完整示例。
Here is a full example of forward geocoding.
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];
}];
这篇关于在iOS 5中将CLPlacemark放在地图上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!