ピンの代わりに画像を地図に表示するにはどうすればいいですか?これまでのところ、私はタップでピンを追加することしかできません。 .mのサンプルコードは、iOSプログラミングをまだ慣れていないので非常に役に立ちます。iOS MapKitカスタムピン
16
A
答えて
53
#pragma mark -
#pragma mark MKMapView delegate
- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
return nil;
static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
if(annotationView)
return annotationView;
else
{
MKAnnotationView *annotationView = [[[MKAnnotationView alloc] initWithAnnotation:annotation
reuseIdentifier:AnnotationIdentifier] autorelease];
annotationView.canShowCallout = YES;
annotationView.image = [UIImage imageNamed:@"someImage.png"];
UIButton* rightButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[rightButton addTarget:self action:@selector(writeSomething:) forControlEvents:UIControlEventTouchUpInside];
[rightButton setTitle:annotation.title forState:UIControlStateNormal];
annotationView.rightCalloutAccessoryView = rightButton;
annotationView.canShowCallout = YES;
annotationView.draggable = YES;
return annotationView;
}
return nil;
}
編集:私はMKAnnotationView
についてあなたのすべてを説明できたが、私はあなたが他のソースからよりもはるかに良い説明するApple社が提供するドキュメントを見つけるだろうと思い
。リンクの概要セクションを確認してください。
https://developer.apple.com/documentation/mapkit/mkannotationview
6
ゴーのXcodeの主催して、ドキュメントに移動し、それが注釈で画像を含むとマップの一例を示しているweatherMap検索します。
0
#pragma mark -
#pragma mark MKMapView delegate
-(void)addAllPinsOnMapView
{
MKCoordinateRegion region = mapViewOffer.region;
region.center = CLLocationCoordinate2DMake(12.9752297537231, 80.2313079833984);
region.span.longitudeDelta= 0.1f;
region.span.latitudeDelta= 0.1f;
[mapViewOffer setRegion:region animated:YES];
mapViewOffer.delegate=self;
arrMapPin=[[NSMutableArray alloc] init];
NSArray *name=[[NSArray alloc]initWithObjects:
@"Title1",
@"Title2",
@"Title3", nil];
NSMutableArray *arrCoordinateStr = [[NSMutableArray alloc] initWithCapacity:name.count];
[arrCoordinateStr addObject:@"12.970760345459,80.2190093994141"];
[arrCoordinateStr addObject:@"12.9752297537231,80.2313079833984"];
[arrCoordinateStr addObject:@"12.9788103103638,80.2412414550781"];
for(int i = 0; i < name.count; i++)
{
NSArray *components = [[arrCoordinateStr objectAtIndex:i] componentsSeparatedByString:@","];
double latitude = [components[0] doubleValue];
double longitude = [components[1] doubleValue];
MKPointAnnotation *mapPin = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
mapPin.title = [name objectAtIndex:i];
mapPin.coordinate = coordinate;
[mapViewOffer addAnnotation:mapPin];
}
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:
(MKAnnotationView *)view
{
NSLog(@"%@",view.annotation.title);
NSLog(@"%f",view.annotation.coordinate.latitude);
NSLog(@"%f",view.annotation.coordinate.longitude);
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(calloutTapped:)];
[view addGestureRecognizer:tapGesture];
}
-(void)calloutTapped:(UITapGestureRecognizer *) sender
{
NSLog(@"Callout was tapped");
MKAnnotationView *view = (MKAnnotationView*)sender.view;
id <MKAnnotation> annotation = [view annotation];
if ([annotation isKindOfClass:[MKPointAnnotation class]])
{
//[self performSegueWithIdentifier:@"annotationDetailSegue" sender:annotation];
OfferDetailsViewController *objOfferDetailsViewController = [[OfferDetailsViewController alloc]init];
[self.navigationController pushViewController:objOfferDetailsViewController animated:YES];
}
}
- (MKAnnotationView *)mapView:(MKMapView *)theMapView
viewForAnnotation:(id <MKAnnotation>)annotation
{
MKAnnotationView *pinView = nil;
static NSString *defaultPinID = @"annotationViewID";
pinView = (MKAnnotationView *)[mapViewOffer dequeueReusableAnnotationViewWithIdentifier:defaultPinID];
if (pinView == nil){
pinView = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:defaultPinID];
}
pinView.canShowCallout = YES;
pinView.image = [UIImage imageNamed:@"placeholder"];
UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
[infoButton addTarget:self action:@selector(infoButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
pinView.rightCalloutAccessoryView = infoButton;
return pinView;
}
+0
長いコードスニペットを投稿する前にいくつかの説明を追加してください。 –
関連する問題
- 1. のiOS - スウィフトMapKit
- 2. のiOS MapKit -
- 3. iOS MapKitラベルパークマップ上
- 4. OpenCv - iOS MapKit conflict
- 5. MapKit iOS 9 detailCalloutAccessoryView usage
- 6. IOSマップ(Google Map APIとMapKit?)
- 7. MapKitの実装iOS Xcode
- 8. iOS Mapkitカスタム吹き出し
- 9. iOS 5 MapKit、MKPlacemark、iOS 5でiOS 4.3アプリを実行中
- 10. iOSのスウィフトMapKit MKAnnotationに準拠クラスが
- 11. ios MapKitでストーリーボードを使用するカスタムアノテーションビュー
- 12. iOS Google Maps SDKとMapKitスクロールの比較
- 13. 計算距離iOS MapKit CLLocationを使用
- 14. iOS 11.2 MapKitがクラスタリングしていない
- 15. IOS 5 - geoタグtwitter data with mapkit
- 16. Bingマップ、カスタムピンが消えて
- 17. カスタムピン注釈ビューの作成方法
- 18. MapKit repsondsToSelector 4.3.3
- 19. MapKit
- 20. カスタムピン画像を表示しない
- 21. performSelectorInBackgroundとMapKit
- 22. iOS SDK - MapKit MKAnnotationViewの質問 - 場所と複数の注釈?
- 23. IOS Mapkit - 私はマップ-キットでiPhoneアプリケーションを作りたい
- 24. MKTileOverlayとPINCacheライブラリのiOS/MapKitキャッシュ管理の問題
- 25. 独自のマップをMapKit iOSに追加する
- 26. iOS 5 MapKitがズーム/パン時にオーバーレイでクラッシュする
- 27. iOS MapKit注釈がすべて追加されていない
- 28. MapKit iOSレンダラーのオーバーライドが制御不能になる
- 29. ios mapkitマップをタップしてアノテーションコールアウトを閉じる
- 30. IOS - Mapkitクラッシュ - xcode 4.2と自動リファレンスカウント(ARC)のバグですか?
少し探索は長い道のりを行く:) http://stackoverflow.com/questions/4579397/iphone-mapkit-adding-custom-image-and-pins-to-annotationsともします。http:/ /stackoverflow.com/questions/7124028/change-pin-design –