用于多站点的Google Maps URL Schema

时间:2017-11-09 14:12:27

标签: ios google-maps url-scheme

我想在iOS上使用网址方案打开Goog​​le地图应用,以显示多个停靠点的路线。

用于测试的网址是:

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

我使用comgooglemaps://尝试了很多配置方案而没有成功。

1 个答案:

答案 0 :(得分:2)

您可以阅读Google Maps documentation以打开该应用。

为简化起见,这是您需要遵循的格式:

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

在swift中你会做这样的事情,注意回调选项,如果你不想回到你的应用程序,你可以选择不拥有它:

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.")
}

编辑:要使用坐标,请按以下方式使用:

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

修改2:对于地图上的更多点,使用+to:Latitude,Longtitude将坐标附加到daddr参数

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