iPhone の MapKit マップにデフォルトのピンの代わりに独自の画像を表示することはできますか?
私は、Google Latitude のように友人の場所を表示するアプリケーションに取り組んでおり、その場所で友人の画像を表示する必要があります。
JavaScript の Google マップを使用することは可能ですが、誰かが MapKit ベースのマップのサンプル コードを提供できるかどうか知りたいです。
iPhone の MapKit マップにデフォルトのピンの代わりに独自の画像を表示することはできますか?
私は、Google Latitude のように友人の場所を表示するアプリケーションに取り組んでおり、その場所で友人の画像を表示する必要があります。
JavaScript の Google マップを使用することは可能ですが、誰かが MapKit ベースのマップのサンプル コードを提供できるかどうか知りたいです。
はい、可能です。そのためには、MKPinAnnotationView の代わりに MKAnnotationView を使用する必要があります。また、annotation.animatesDrop プロパティを使用しないでください。
以下は、viewForAnnotation で使用できるサンプル コードです。
annotation = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"try"];
annotation.canShowCallout = YES;
annotation.image = [UIImage imageNamed:@"image.png"];
return annotation;
画像のフレームを設定することもできます。上記のコードでは、この単純な変更を行う必要があります。
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"];
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];