2010-01-14 30 views
2

我使用MapView,併爲其設置了註釋(紫色針腳)和我的用戶位置(這是一個藍色圓圈)。 由於紫色針註釋會移動,我必須移除並將它們設置爲新的地圖。iPhone - 刪除地圖的註釋,但不是我的

我設置:

CLLocationCoordinate2D coordinate; 
coordinate.latitude = 49.2802; 
coordinate.longitude = -123.1182; 
NSUInteger count = 1; 
for(int i = 0; i < 10; i++) { 
    CGFloat latDelta = rand()*.035/RAND_MAX - .02; 
    CGFloat longDelta = rand()*.03/RAND_MAX - .015; 
    CLLocationCoordinate2D newCoord = {coordinate.latitude+latDelta, coordinate.longitude+longDelta}; 
    MyMapAnnotation* annotation = [[MyMapAnnotation alloc] initWithCoordinate:newCoord andID:count++]; 
    [mapView addAnnotation:annotation]; 
    [annotation release]; 
} 

在此之前,我做了

[mapView removeAnnotations:mapView.annotations]; 

但此行也與藍點刪除我的位置! 我怎樣才能做到這一點,而無需刪除我的位置。

非常感謝&最好的問候。

回答

3

一個非常簡單的方法來做到這一點是包括循環之前這條線,你刪除註釋:

self.mapView.showsUserLocation = NO; 

,然後在循環後,把用戶位置回

self.mapView.showsUserLocation = YES; 

編輯:我剛剛看到你沒有通過位置循環刪除它們。我不確定這是否會按照您的方式工作。

+0

嗯,我怎麼能讓它變得更好? 因爲我做: - (MKAnnotationView *)的MapView:(的MKMapView *)mapViewLocal viewForAnnotation:(ID )註釋{ \t如果(註釋== mapViewLocal.userLocation){ \t \t mapViewLocal.userLocation.title = @ 「測試」; \t \t mapViewLocal.userLocation.subtitle = @「Test Sub」; \t \t [mapViewLocal setRegion:MKCoordinateRegionMakeWithDistance(mapViewLocal.userLocation.coordinate,3000,3000)animated:NO]; \t \t return nil; \t} ... 因此,我將始終將我的位置設置在中心位置。藍點不出現。我必須移動MapView,然後顯示藍點。 – Tim 2010-01-14 11:47:03

+0

要獲得帶註釋的中心地圖視圖,請遍歷它們並查找最大和最小經度和緯度,然後使用這些設置區域跨度和中心。如果您想在註釋中包含用戶位置,請確保使用我上面編寫的方法顯示它。 'MKMapView'有一個名爲'annotations'的屬性,它存儲所有的註釋(包括用戶位置)。如果您只想將地圖置於用戶位置上,請使用'setCenterCoordinate:animated:' – 2010-01-14 14:49:49

+0

如果您可以節省5美元,本教程確實幫助我瞭解地圖視圖:http://pragprog.com/screencasts/v-bdmapkit/ using-map-kit – 2010-01-14 14:51:10