0

我正在开发一个应用程序来显示特定邮政编码中可用的商店。我从当前位置开始。我的当前位置出现蓝色脉动点。当我输入邮政编码时,我可以在地图视图中显示注释。我有一个“当前位置”按钮,可以再次返回当前位置。但是第二次我没有得到蓝点?我如何得到它,这是代码:

- (void)showCurrentLocation 
{  
 self.mapView.showsUserLocation = YES;
    GPSAnnotation *annotation = [[GPSAnnotation alloc] initWithCoordinate:self.mapView.userLocation.coordinate];

    annotation.title = @"Location";
    [self.mapView addAnnotation:annotation];
    [annotation release];    

    MKCoordinateRegion zoomIn;
    zoomIn.center.latitude = self.mapView.userLocation.coordinate.latitude;
    zoomIn.center.longitude=self.mapView.userLocation.coordinate.longitude;

    zoomIn.span.latitudeDelta = .1f;
    zoomIn.span.longitudeDelta =.1f;

    self.mapView.showsUserLocation = YES;
    [self.mapView setRegion:zoomIn animated:TRUE];
}

// annotation view 

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(GPSAnnotation *)annotation
{
    if ([[annotation title] isEqualToString:@"Location"]) 
    {
        MKAnnotationView *annotationView=[[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:nil] autorelease];

        annotationView = [self.mapView dequeueReusableAnnotationViewWithIdentifier:@"blueDot"];
        annotationView.annotation = annotation;
        return  annotationView;
    }

    else  if ([annotation isKindOfClass:[MKUserLocation class]])
    {        
        return nil;
    }
}
4

1 回答 1

4

您是否在某处制作了 [self.mapView removeAnnotations:self.mapView.annotations] 来清空地图?这是一个常见错误,因为您还通过这样做删除了用户位置。

于 2011-07-23T08:59:06.700 回答