开发者

Remove previously placemark from mkmapview

开发者 https://www.devze.com 2023-03-15 21:19 出处:网络
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.

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];
0

精彩评论

暂无评论...
验证码 换一张
取 消