目前我可以在地圖上放置引腳。現在我想讓註解標題顯示引腳被丟棄的地址。當引腳在地圖上丟棄時,在註釋中顯示地址
我看了一下這一點,但不能讓我的工作:
Set annotation's title as current address
代碼在我ViewController.m
更新。
- (void)addPinToMap:(UIGestureRecognizer *)gestureRecognizer
{
if (gestureRecognizer.state != UIGestureRecognizerStateBegan)
return;
CGPoint touchPoint = [gestureRecognizer locationInView:self.map];
CLLocationCoordinate2D touchMapCoordinate =
[self.map convertPoint:touchPoint toCoordinateFromView:self.map];
CLLocation *currentLocation = [[CLLocation alloc]
initWithLatitude:touchMapCoordinate.latitude
longitude:touchMapCoordinate.longitude];
[self.geocoder reverseGeocodeLocation:currentLocation completionHandler:^(NSArray *placemark, NSError *error) {
//initialize the title to "unknown" in case geocode has failed...
NSString *annTitle = @"Address unknown";
//set the title if we got any placemarks...
if (placemark.count > 0)
{
CLPlacemark *topResult = [placemark objectAtIndex:0];
annTitle = [NSString stringWithFormat:@"%@ %@ %@ %@", topResult.country, topResult.locality, topResult.subLocality, topResult.thoroughfare];
}
//now create the annotation...
MapAnnotation *toAdd = [[MapAnnotation alloc]init];
toAdd.coordinate = touchMapCoordinate;
toAdd.title = annTitle;
//toAdd.title = @"Title";
toAdd.subtitle = @"Subtitle";
[self.map addAnnotation:toAdd];
}];
}
我目前在嘗試做同樣的事情的過程! – logixologist