地図上に複数の場所や注釈ピンを表示することができます。ユーザーがクリックするとタイトルが付いたポップアップが表示されます。ポップアップで「>」ボタンをクリックしたときにユーザーに経路案内を許可するにはマップアノテーションピンをクリックすると、ユーザーが「道順を取得する」方法を教えてください
0
A
答えて
0
2つの操作が必要です: 1.地図ピンから位置を取得します 2. Googleマップを開きますURL。ここで
は、それが(これのいくつかはhereから来た)
CLLocationCoordinate2D start = myMapView.userLocation.location.coordinate;
CLLocationCoordinate2D destination = [pinSelected.annotation coordinate];
NSString *googleMapsURLString = [NSString stringWithFormat:@"http://maps.google.com/?saddr=%1.6f,%1.6f&daddr=%1.6f,%1.6f",
start.latitude, start.longitude, destination.latitude, destination.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:googleMapsURLString]];
0
コードのiOS 5.xとのiOS 6.xの上の異なる振る舞いをどのように動作するかです注釈は "toAnnotation" で、以下のコードが動作すると仮定します
- (void)openMap
{
Class itemClass = [MKMapItem class];
if (itemClass && [itemClass respondsToSelector:@selector(openMapsWithItems:launchOptions:)]) { // iOS 6.x and later
MKMapItem *currentLocation = [MKMapItem mapItemForCurrentLocation];
MKMapItem *toLocation = [[MKMapItem alloc]
initWithPlacemark:[[MKPlacemark alloc]
initWithCoordinate:CLLocationCoordinate2DMake(toAnnotation.coordinate.latitude, toAnnotation.coordinate.longitude)
addressDictionary:nil]];
toLocation.name = toAnnotation.title;
[MKMapItem openMapsWithItems:[NSArray arrayWithObjects:currentLocation, toLocation, nil]
launchOptions:[NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeDriving, [NSNumber numberWithBool:YES], nil]
forKeys:[NSArray arrayWithObjects:MKLaunchOptionsDirectionsModeKey, MKLaunchOptionsShowsTrafficKey, nil]]];
} else { // iOS 5.1 and earlier
NSMutableString *mapURL = [NSMutableString stringWithString:@"http://maps.google.com/maps?"];
[mapURL appendFormat:@"saddr=Current Location"];
[mapURL appendFormat:@"&daddr=%f,%f", toAnnotation.coordinate.latitude, toAnnotation.coordinate.longitude];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:[mapURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
}
}
0
は、まず、あなたは、ビューcontroller.hファイル内に必要Viewcontroller.m
で、その後- (IBAction)startWithOnePlacemark:(id)sender
{
CLLocationCoordinate2D bigBenLocation = CLLocationCoordinate2DMake(51.50065200, -0.12483300);
MKPlacemark *bigBenPlacemark = [[MKPlacemark alloc] initWithCoordinate:bigBenLocation addressDictionary:nil];
MKMapItem *bigBenItem = [[MKMapItem alloc] initWithPlacemark:bigBenPlacemark];
bigBenItem.name = @"Big Ben";
[bigBenItem openInMapsWithLaunchOptions:nil];
// Note: use initWithPlacemark: to initialize with CLPlacemark
}
- (IBAction)startWithMultiplePlacemarks:(id)sender
{
CLLocationCoordinate2D bigBenLocation = CLLocationCoordinate2DMake(51.50065200, -0.12483300);
MKPlacemark *bigBenPlacemark = [[MKPlacemark alloc] initWithCoordinate:bigBenLocation addressDictionary:nil];
MKMapItem *bigBenItem = [[MKMapItem alloc] initWithPlacemark:bigBenPlacemark];
bigBenItem.name = @"Big Ben";
CLLocationCoordinate2D westminsterLocation = CLLocationCoordinate2DMake(51.50054300, -0.13570200);
MKPlacemark *westminsterPlacemark = [[MKPlacemark alloc] initWithCoordinate:westminsterLocation addressDictionary:nil];
MKMapItem *westminsterItem = [[MKMapItem alloc] initWithPlacemark:westminsterPlacemark];
westminsterItem.name = @"Westminster Abbey";
NSArray *items = [[NSArray alloc] initWithObjects:bigBenItem, westminsterItem, nil];
[MKMapItem openMapsWithItems:items launchOptions:nil];
}
- (IBAction)startInDirectionsMode:(id)sender
{
CLLocationCoordinate2D bigBenLocation = CLLocationCoordinate2DMake(51.50065200, -0.12483300);
MKPlacemark *bigBenPlacemark = [[MKPlacemark alloc] initWithCoordinate:bigBenLocation addressDictionary:nil];
MKMapItem *bigBenItem = [[MKMapItem alloc] initWithPlacemark:bigBenPlacemark];
bigBenItem.name = @"Big Ben";
CLLocationCoordinate2D westminsterLocation = CLLocationCoordinate2DMake(51.50054300, -0.13570200);
MKPlacemark *westminsterPlacemark = [[MKPlacemark alloc] initWithCoordinate:westminsterLocation addressDictionary:nil];
MKMapItem *westminsterItem = [[MKMapItem alloc] initWithPlacemark:westminsterPlacemark];
westminsterItem.name = @"Westminster Abbey";
NSArray *items = [[NSArray alloc] initWithObjects:bigBenItem, westminsterItem, nil];
NSDictionary *options = @{MKLaunchOptionsDirectionsModeKey: MKLaunchOptionsDirectionsModeWalking};
[MKMapItem openMapsWithItems:items launchOptions:options];
}
を
- (IBAction)startWithOnePlacemark:(id)sender;
- (IBAction)startWithMultiplePlacemarks:(id)sender;
- (IBAction)startInDirectionsMode:(id)sender;
を書きます
Mapkit、AddressBook、CoreLocation Frameworkを追加する
関連する問題
- 1. クリックした特定のJbuttonの取得方法を教えてください。
- 2. URLを絶対パスで取得する方法を教えてください。
- 3. Ionic - AngularJS - クリック時にビューステートをリフレッシュする方法を教えてください。
- 4. JMenu要素をクリックする方法を教えてください。
- 5. ラジオボタンのテキストをクリック可能にする方法を教えてください。
- 6. ユーザーがGoogleマップにパスを描く方法を教えてください。
- 7. ユーザーにグループメンバーシップを要求する方法を教えてください。
- 8. ハッシュセットをアルファベット順に並べる方法を教えてください。
- 9. ユーザーにアップロードディレクトリを選択させる方法を教えてください。
- 10. Eclipseプラグインをアンパックする方法を教えてください。
- 11. タブローを定義する方法を教えてください
- 12. Android - アイコンをタッチする方法を教えてください。
- 13. ImageView Androidをトリミングする方法を教えてください。
- 14. ストリームフィルタをエコーする方法を教えてください。
- 15. ジェンキンズを「ピップインストール」する方法を教えてください。
- 16. LDAPからユーザー名を取得する - 何が間違っているか教えてください。
- 17. ポイントから消える方法を教えてください。
- 18. ImageButtonをクリックすると電子メールコンポーザーを直接開く方法を教えてください。
- 19. GridViewのユーザー名列をOutlookで開く方法を教えてください。
- 20. ReferencePropertyを使用すると、日付順に注文する方法を教えてください。
- 21. 剣道図を使用して、凡例アイテムをハイパーリンクにする方法を教えてください。
- 22. EclipseでAVDを「見る」方法を教えてください。
- 23. IBOutletをプロパティとして定義する方法を教えてください。
- 24. 長時間実行されるVBAタスクをユーザーが終了する方法を教えてください。
- 25. このビューコンテキストが現在のモデルの名前を取得する方法を教えてください。 APIの
- 26. ルビースクリプトが与えられていることを理解する方法を教えてください。
- 27. Swingアプリケーションに触れる方法を教えてください。
- 28. ブックマークレットを一度だけ実行する方法を教えてください。
- 29. reload uitableviewでuilabelとuiimageviewをオーバーラップする方法を教えてください。
- 30. ./configureにLDFLAGSとCPPFLAGSを指定する方法を教えてください。