0

MKMapView クラスがあり、画像で表されるユーザーの位置を地図上に表示したいと考えています。だから、私はこのチュートリアルを読みました: http://www.switchonthecode.com/tutorials/getting-your-location-in-an-iphone-application

この男は、ビューで locationmanager を使用します。MKMapView で使用する必要があります。

私にとって、これを行う最善の方法は、ユーザーの位置を制御するためだけにクラスを作成することですか? これどうやってするの?

ありがとう!!

4

2 に答える 2

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;    
}

このチュートリアルを参照してください。

于 2012-11-14T04:26:52.600 に答える
0

まず、場所をマップに表示します。

yourMapView.showsUserLocation = YES;

次に、ユーザーの場所の注釈ビューを表示するデリゲート メソッドを処理する必要があります。

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

を正しく設定しdelegateてください。MKMapView

于 2012-11-14T02:13:11.467 に答える