I have a item list table. When I select a row of my table, I show a view with more information and a map with the placemark. The used code is below:
MKCoordinateRegion region;
CLLocationCoordinate2D coordinate = {lat,longt};
region.center.latitude = coordinate.latitude;
region.center.longitude = coordinate.longitude;
region.span.latitudeDelta = 0.3;
region.span.longitudeDelta = 0.3;
[self.mapView setRegion:region animated:YES];
MKPlacemark *mPlacemark = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
[mapView addAnnotation:mPlacemark];
[mPlacemark release];
The problem is that when I select another item after the previously selected i开发者_JAVA技巧tem in my map displays the new placemark and those previously. How to remove the previously placemark from my map??
Try with removing the previously added placemark.
- (void)removeAnnotation:(id < MKAnnotation >)annotation
Like :
Declare mPreviousPlacemark
as the retain
property of your class.
[mapView removeAnnotation:mPreviousPlacemark];
[mapView addAnnotation:mPlacemark];
self.mPreviousPlacemark = mPlacemark;
[mPlacemark release];
精彩评论