iOS App通過URL調用Google地圖導航

來源:互聯網
上載者:User

標籤:

1、給iPhone安裝google map app,因為之後會使用這個程式進行導航

2、在自己的App中需要進行導航的地方,加入下列代碼

if ([[UIApplication sharedApplication] canOpenURL:     [NSURL URLWithString:@"comgooglemaps://"]]) {  [[UIApplication sharedApplication] openURL:   [NSURL URLWithString:@"comgooglemaps://?center=40.765819,-73.975866&zoom=14&views=traffic"]];} else {  NSLog(@"Can‘t use comgooglemaps://");}

這裏的if主要就是判斷手機中是否有google map app.如果有就將url參數傳入google mao app.

舉例:

comgooglemaps://?center=46.414382,10.013988&mapmode=streetview
以center=46.414382,10.013988為中心點顯示地圖

3、導航的參數

實現導航功能的URL會有三個參數,saddr,daddr,directionsmode,以下是google官方提供的介紹。

  • saddr: Sets the starting point for directions searches. This can be a latitude,longitude or a query formatted address. If it is a query string that returns more than one result, the first result will be selected. If the value is left blank, then the user’s current location will be used.
  • daddr: Sets the end point for directions searches. Has the same format and behavior as saddr.
  • directionsmode: Method of transportation. Can be set to: driving, transit, bicycling or walking.

下面以例子來介紹該如何使用

1、官方例子,直接進行兩個點的導航
comgooglemaps://?saddr=Google+Inc,+8th+Avenue,+New+York,+NY&daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York&directionsmode=transit
2、通過經緯度實現兩個點的導航
url = [NSString stringWithFormat:@"comgooglemaps://?saddr=37.782652,-122.410126&daddr=%lf,%lf&directionsmode=driving", targetLocation.latitude, targetLocation.longitude];
3、以手機所在位置為起始點進行導航
url = [NSString stringWithFormat:@"comgooglemaps://?daddr=%lf,%lf&directionsmode=driving", targetLocation.latitude, targetLocation.longitude];

 

iOS App通過URL調用Google地圖導航

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.