2009-09-29 4 views
6

iPhoneのMapKitマップのデフォルトのピンの代わりに独自のイメージを使用できますか?iPhoneのMapKitフレームワークのデフォルトのピンの代わりに画像ですか?

Google Latitudeとよく似た友だちの場所を表示し、友だちの画像をその場所に表示する必要があるアプリケーションに取り組んでいます。

JavaScriptのGoogleマップを使用することは可能ですが、誰かがMapKitベースのマップのサンプルコードを提供できるかどうかを知りたいと思っています。

答えて

14

はい、可能です。 そのためには、MKPinAnnotationViewの代わりにMKA​​nnotationViewを使用する必要があります。 、annotation.animatesDropプロパティは使用しないでください。ここで

あなたはまた、画像のフレームを設定することができ

annotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"]; 
    annotation.canShowCallout = YES; 

    annotation.image = [UIImage imageNamed:@"image.png"]; 


    return annotation; 
+0

ありがとうございました。それはトリックでした。私はそのようなシンプルなトリックを理解していると信じています。 –

2

、あなたがviewForAnnotationに使用できるサンプルコードです。上記のコードでは、この単純な変更を行う必要があります。

UIImage *pinImage = [UIImage imageNamed:@"image.png"]; 

UIImageView *imageView = [[[UIImageView alloc] initWithImage:pinImage] autorelease]; 

     imageView.frame = CGRectMake(-20, 0, 40, 30); 

[annotation addSubview:imageView]; 

そして、我々はあなたが簡単にあなたの必要

MKCoordinateSpanスパンにズームすることができますスパンプロパティを使用して、回線

// annotation.image = [UIImage imageNamed:@"image.png"]; 
0

をコメントに持っています。

MKCoordinateRegion region; 


mapView.scrollEnabled=YES; 
span.latitudeDelta = 100.0;//more value you set your zoom level will increase 
span.longitudeDelta =100.0;//more value you set your zoom level will increase 
mapView.showsUserLocation=YES; 
region.span = span; 


region.center = from.coordinate; 
    [mapView setRegion:region animated:YES]; 
[mapView regionThatFits:region]; 
[mapView addAnnotation:from]; 
関連する問題