注釈メソッド removeAnnotation が呼び出されないため、場所の更新中にマップ上の画像が複製されます。古い場所から画像を削除できるように removeAnnotation メソッドを呼び出す方法。
<pre>
- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation
{
static NSString *AnnotationViewID = @"annotationViewID";
MKAnnotationView *annotationView = (MKAnnotationView *)[map dequeueReusableAnnotationViewWithIdentifier:AnnotationViewID];
if (annotationView == nil)
{
annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:AnnotationViewID] autorelease];
}
annotationView.image = [UIImage imageNamed:@"Bike.png"];
annotationView.annotation = annotation;
return annotationView;
}
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation
{
// here do
//UIImage *pinImage = [UIImage imageNamed:@"Bike.png"];
CLLocation *currentLocation = newLocation;
if(currentLocation != nil)
{
CLLocationCoordinate2D location = CLLocationCoordinate2DMake(currentLocation.coordinate.latitude, currentLocation.coordinate.longitude);
MyAnnotation *annotation = [[MyAnnotation alloc] initWithCoordinates:location title:@"India" subTitle:@"Sarvopari Mall"];
if (newLocation)
{
[self.myMapView removeAnnotation:annotation];
}
[self.myMapView addAnnotation:annotation];
}
}
</pre>