2014-09-05 96 views
1

我現在正在考慮爲iOS的應用程序,它可以發送短信給其他人(沒有互聯網連接)與URL鏈接,讓他們離線指向我的位置本地地圖當他們點擊鏈接的應用程序。 我知道它可以用這種URL來完成:蘋果地圖從當前位置的路線請求URL

http://maps.apple.com/maps?saddr=<their location>&daddr=<my location, filled by my app> 

當然,我可以離開saddr空白,讓他們從開始點自動完成列表中選擇自己當前的位置,但它會帶他們還差1步得到方向。我只是想確保給他們最方便的方式。

如何指導原生地圖應用程序自動獲取短信接收用戶的當前位置通過此URL?我需要一些這樣的事:

http://maps.apple.com/maps?saddr=current_location&daddr=<my location, filled by my app> 

我也想這個鏈接發送給其他平臺的用戶,如與Android用戶,我可以使用:

http://maps.google.com/maps?saddr=current_location&daddr=<my location, filled by my app> 

的Windows Phone(我還不知道):

http://maps.???.com/maps?saddr=current_location&daddr=<my location, filled by my app> 

任何關鍵字或答覆將非常感激!

回答

10

你非常接近!

蘋果地圖:

http://maps.apple.com/maps?saddr=Current%20Location&daddr=<Your Location> 

谷歌地圖:

comgooglemaps-x-callback://?saddr=&daddr=<Your Location> 
+0

我的英雄。謝謝它的作品! – FlySoFast 2015-01-21 03:45:28

+1

這有效。對於谷歌地圖,你不能添加saddr參數,並會工作,蘋果的方式有點笨,當前的位置應該是默認的,但你需要扭轉當前的%20位置。謝謝。 – rr1g0 2015-02-08 00:05:00

+0

我同意。蘋果公司有點落後於那個時代。沒問題 - 很高興能有幫助。 – Spaceship09 2015-02-09 09:50:44

1

如果您正在使用的Objective-C:

NSString *urlString = [NSString stringWithFormat:@"maps.apple.com/maps?saddr=&daddr=%@,%@",destinationLatitude,destinationLongitude]; 
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:urlString]]; 

如果您使用的SWIFT 2.2:

var string = "http://maps.apple.com/?saddr=&daddr=\(destinationLatitude),\(destinationLongitude)" 
    UIApplication.sharedApplication().openURL(NSURL(string: string)!) 

如果您使用的是swift 3.0:

var string = "http://maps.apple.com/?saddr=&daddr=\(destinationLatitude),\(destinationLongitude)" 
    UIApplication.shared.openURL(URL(string: string)!) 
相關問題