6

iPhone の MapKit マップにデフォルトのピンの代わりに独自の画像を表示することはできますか?

私は、Google Latitude のように友人の場所を表示するアプリケーションに取り組んでおり、その場所で友人の画像を表示する必要があります。

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

4

3 に答える 3

14

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

以下は、viewForAnnotation で使用できるサンプル コードです。

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

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


    return annotation;
于 2009-09-29T14:20:15.310 に答える
2

画像のフレームを設定することもできます。上記のコードでは、この単純な変更を行う必要があります。

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

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

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

[annotation addSubview:imageView];

そして、行をコメントする必要があります

// annotation.image = [UIImage imageNamed:@"image.png"];
于 2010-11-29T06:38:18.437 に答える
0

span プロパティを使用すると、必要に応じて簡単にズームできます

MKCoordinateSpan スパン;

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];
于 2013-07-25T07:39:09.997 に答える