2012-04-29 29 views
1

我是CoreLocation和MapKit的新手,我有這個奇怪的問題。基本上,我有一個顯示在UIView中的MKMapView。當我建立了我的MKMapView這樣的:showUserLocation在將MapView委託設置爲self時更改

self.mapView.showsUserLocation = YES; 
//self.mapView.delegate = self; 

我得到這個(1):

enter image description here

但當我去掉第二行,我得到這個(2)我覺得這不可思議。

enter image description here

我怎麼能這樣做設置的MKMapView自我的代表,但仍得到(1)

感謝

+0

當您切換兩條線的順序時會發生什麼? –

+0

沒什麼,我仍然得到(2) –

回答

3

你在覆蓋註釋(viewForAnnotation方法)的控制器?在我看來,當你將委託設置爲self時,註解被覆蓋。

如果您在類中更改註釋,請添加以下行。這將防止更改「當前位置」點的註釋。

- (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>)annotation 
{ 
    static NSString *AnnotationViewID = @"annotationViewID"; 

    // Check if its the annotation for displaying the current position 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     return nil; 
    } 

    // Your annotation code 

} 
+0

謝謝,它的工作原理。但是,你的意思是'重寫我的控制器中的註釋'。 –

+0

我曾經有過類似的問題。我在哪裏更改註釋圖標。我覆蓋了上面代碼示例中所示的註釋方法。但是我覆蓋了所有註釋(包括當前位置圖標)。在你自己委派的Controller類中,你有沒有像上面那樣實現的方法: - (MKAnnotationView *)mapView:(MKMapView *)map viewForAnnotation:(id )註釋? – Prine