2012-11-14 38 views

回答

0

首先,你想要的位置顯示在地圖上:

yourMapView.showsUserLocation = YES;

然後,你需要處理的委託方法爲用戶位置顯示annotationview:

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation { 
    if ([annotation isKindOfClass:[MKUserLocation class]]) { 
     // Create a custom MKAnnotationView here that will display your image. 
    } 
} 

製作確定你的MKMapView正確設置了delegate

0

爲此,您需要實施MKAnnotation & MKMapView代表。

執行此方法將默認引腳更改爲自定義圖像。

- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation 
    { 
    if ([annotation isKindOfClass:[MKUserLocation class]]) 
    { 
     // Create a custom MKAnnotationView here that will display your image. 
     //user current location 
    } 

    static NSString *identifier = @"MyLocation"; 
    if ([annotation isKindOfClass:[MyLocation class]]) 
    { 

     MKPinAnnotationView *annotationView = (MKPinAnnotationView *) [_mapView dequeueReusableAnnotationViewWithIdentifier:identifier]; 
     if (annotationView == nil) 
     { 
      annotationView = [[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier]; 
     } 
     else 
     { 
      annotationView.annotation = annotation; 
     } 

     annotationView.enabled = YES; 
     annotationView.canShowCallout = YES; 
     annotationView.image=[UIImage imageNamed:@"yourImage.png"]; 

     return annotationView; 
    } 

    return nil;  
} 

請參考tutorial

相關問題