就可以得到當前位置的使用CLLocationManager,或者其包裝DKLocationManager(在github)的座標,創建通過Keith Pitt。
一旦你的座標,你可以使用下面的代碼示例。
+ (void) openDirectionFrom:CLLocation* currentLocation To:(NSString*) daddr {
NSString* urlStr;
NSString* saddr = @"Current+Location";
if ([[UIDevice currentDevice] systemVersion] floatValue] >=6) {
//iOS 6+, Should use map.apple.com. Current Location doesn't work in iOS 6 . Must provide the coordinate.
if ((currentLocation.coordinate.latitude != kCLLocationCoordinate2DInvalid.latitude) && (currentLocation.coordinate.longitude != kCLLocationCoordinate2DInvalid.longitude)) {
//Valid location.
saddr = [NSString stringWithFormat:@"%f,%f", currentLocation.coordinate.latitude,currentLocation.coordinate.longitude];
urlStr = [NSString stringWithFormat:@"http://maps.apple.com/maps?saddr=%@&daddr=%@", saddr, daddr];
} else {
//Invalid location. Location Service disabled.
urlStr = [NSString stringWithFormat:@"http://maps.apple.com/maps?daddr=%@", daddr];
}
} else {
// < iOS 6. Use maps.google.com
urlStr = [NSString stringWithFormat:@"http://maps.google.com/maps?saddr=%@&daddr=%@", saddr, daddr];
}
[(UIApplicationWithEvents*)[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlStr]];
}
你忘了網址地方的文檔。 –
Woops抱歉回到你這麼晚這裏是鏈接文件,雖然它沒有多大幫助。 http://developer.apple.com/library/ios/#featuredarticles/iPhoneURLScheme_Reference/Articles/MapLinks.html#//apple_ref/doc/uid/TP40007894-SW1 –
使用20%,而不是正(+)符號。加號不是在網址中添加空格的正確方法。一些搜索引擎和表單提交使用plus作爲空間的替代,但正確的方法是%20。我已經在iPad上進行了驗證,當文本爲&saddr = Current%20Location – nivs1978