Google Maps URL Schema for multi stops [closed]

我怕爱的太早我们不能终老 提交于 2020-12-10 10:44:30

问题


I would like to open Google Maps app on iOS using the url scheme for showing directions with multiple stops.

The web url for testing is:

https://google.com/maps/dir//49.54643774,22.28223445/49.54679476,22.28170513/49.54726735,22.28154318/49.54760869,22.28156607/49.54820312,22.2815506/49.54856556,22.28146425/49.54907329,22.28133231/49.54989807,22.28207924/49.55017454,22.2824851/49.55064392,22.28306989/49.5508548,22.28325003/49.55143275,22.28381447/49.55169439,22.28410868/49.5520271,22.28443534

I tried many configurations of the app scheme using comgooglemaps:// without success.


回答1:


You can read the Google Maps documentation for opening the app.

To simplify it, this is the format you need to follow:

comgooglemaps://?saddr=Google,+1600+Amphitheatre+Parkway,+Mountain+View,+CA+94043&daddr=Google+Inc,+345+Spear+Street,+San+Francisco,+CA&center=37.422185,-122.083898&zoom=10

in swift you would do something like this, take note of the callback option, you can choose to not have it if you don't want to return to your app:

let testURL = URL(string: "comgooglemaps-x-callback://")!
if UIApplication.shared.canOpenURL(testURL) {
  let directionsRequest = "comgooglemaps-x-callback://" +
    "?daddr=John+F.+Kennedy+International+Airport,+Van+Wyck+Expressway,+Jamaica,+New+York" +
    "&x-success=sourceapp://?resume=true&x-source=AirApp"

  let directionsURL = URL(string: directionsRequest)!
  UIApplication.shared.openURL(directionsURL)
} else {
  NSLog("Can't use comgooglemaps-x-callback:// on this device.")
}

Edit: To use coordinates, use it this way:

comgooglemaps://?saddr=52.3668563,4.8890813&daddr=52.357516,4.902319&zoom=10

Edit 2: For for more points on the map append coordinate using +to:Latitude,Longtitude to the daddr parameter

comgooglemaps://?saddr=52.3668563,4.8890813&daddr=52.357516,4.902319+to:52.357786,4.891913&zoom=10


来源:https://stackoverflow.com/questions/47204005/google-maps-url-schema-for-multi-stops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!