問(wèn)題描述
我正在嘗試從我的 iPhone SDK 應(yīng)用程序啟動(dòng)地圖應(yīng)用程序.現(xiàn)在我可以啟動(dòng)帶有路線的地圖應(yīng)用程序,但它會(huì)轉(zhuǎn)到路線概覽,并且不使用 Siri 和語(yǔ)音導(dǎo)航來(lái)提供轉(zhuǎn)彎路線.
I am trying to launch the maps app from my iPhone SDK app. Right now I can launch the maps app with directions but it goes to an overview of the directions and doesn't use Siri and the voice navigation to give turn by turn directions.
目前我有一個(gè)啟動(dòng)此代碼的按鈕...
currently I have a button that launches this code...
NSString *address = viewedObject.addressFull;
NSString *url = [NSString stringWithFormat: @"http://maps.apple.com/maps?saddr=%f,%f&daddr=%@", here.latitude, here.longitude, [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];
推薦答案
iOS 6 提供了一種啟動(dòng)地圖的新方法,使用 MKMapItem
中的 openMapsWithItems:
.這是我使用的一個(gè)片段,它提供從當(dāng)前位置到所提供坐標(biāo)的步行或駕車路線:
With iOS 6 there's a new way to launch maps, using openMapsWithItems:
in MKMapItem
. Here's a snippet that I use that provides walking or driving directions from current location to the provided coordinates:
// iOS 6.0+ only
MKPlacemark* destPlace = [[[MKPlacemark alloc] initWithCoordinate:coordinate addressDictionary:nil] autorelease];
MKMapItem* destMapItem = [[[MKMapItem alloc] initWithPlacemark:destPlace] autorelease]; destMapItem.name = stationItem.title;
NSArray* mapItems = [[[NSArray alloc] initWithObjects: destMapItem, nil] autorelease];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
walking ? MKLaunchOptionsDirectionsModeWalking : MKLaunchOptionsDirectionsModeDriving,
MKLaunchOptionsDirectionsModeKey, nil];
[MKMapItem openMapsWithItems:mapItems launchOptions:options];
按照您的方式,如果在 iOS 6 之前的設(shè)備上運(yùn)行,您仍然需要這樣做,您需要在 URL 中包含 dirflg
以請(qǐng)求步行或駕車路線:
The way you are doing it, which you still have to do if running on pre-iOS 6 devices, you need to include the dirflg
in the URL to request walking or driving directions:
// pre iOS 6 code
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=%c",
currentLocation.coordinate.latitude,
currentLocation.coordinate.longitude,
destination.coordinate.latitude,
destination.coordinate.longitude,
walking ? 'w' : 'd'];
這篇關(guān)于iPhone SDK 6 啟動(dòng)帶有語(yǔ)音導(dǎo)航方向的地圖的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!