1

私はIOS6用のアプリを開発しています。
マップアプリケーションを実行し、ユーザーをナビゲートできるように開始と宛先を渡したいです。

UIApplication *app = [UIApplication sharedApplication];

    NSString *coordinates = [NSString stringWithFormat:@"http://maps.google.com/maps?daddr=%f,%f&saddr=%f,%f", ...];

    [app openURL:[NSURL URLWithString: coordinates]];

このコードはシミュレーターのブラウザーでグーグルマップを開き、デバイスのアプリをマップすると思いましたが、デバイスではブラウザーのグーグルマップを実行します。
私は何か間違ったことをしていますか?

4

4 に答える 4

7

ご存じない場合は、AppleはGoogleマップを使用しなくなったため、Appleマップには新しいURLスキームを使用する必要があります。(注:iOS 5をサポートしている場合は、両方を使用する必要があります。GoogleマップスキームとAppleマップ)

クエリの例を次に示しますhttp://maps.apple.com/maps?daddr=San+Francisco,+CA&saddr=cupertino

そのためのドキュメントは次のとおりです。AppleMapsのURLスキーム

于 2012-09-26T16:56:03.357 に答える
2

MKPlacemarkオブジェクトがある場合の別のオプション:

// placemark is your MKPlacemark object
MKMapItem* destination =  [[MKMapItem alloc] initWithPlacemark:placemark];

if([destination respondsToSelector:@selector(openInMapsWithLaunchOptions:)])
{
   // Using iOS6 native maps app
   [destination openInMapsWithLaunchOptions:@{MKLaunchOptionsDirectionsModeKey:MKLaunchOptionsDirectionsModeDriving}];      
}
else
{
   // Using iOS5 which has the Google Maps application
   NSString *currentLocation = @"Current%20Location";
   NSString *routeString = [NSString stringWithFormat:@"%@saddr=%@&daddr=%@", kMapsBaseUrl, currentLocation, address.mapAddress];
   [[UIApplication sharedApplication] openURL:[NSURL URLWithString:routeString]];
}
于 2012-09-26T17:11:35.497 に答える
2

これは私がiOS8で使用しているものです。

まず、URL @ "comgooglemaps://"を開こうとします。これが機能する場合は、Googleマップアプリがインストールされていることを意味するため、アプリを開くことができます。

それが機能しない場合は、アプリがありません。SafariでGoogleマップを開くだけです。

どちらの場合も、クエリを渡しますq=London

if([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps://"]]){ //open google maps app
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://?q=London"]];
}
else{ //open browser 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"http://maps.google.com/maps?q=London"]];
}
于 2015-07-30T14:07:21.093 に答える
1
-(void)openAddressOnNativeMapApp{
NSString *addressOnMap = @"cupertino";  //place name
NSString* addr = [NSString stringWithFormat:@"http://maps.apple.com/?q=%@",addressOnMap];
NSURL* url = [[NSURL alloc] initWithString:[addr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:url];

}

詳細については、AppleDocにアクセスしてネイティブマップアプリを開いてください

于 2014-07-16T08:38:50.870 に答える