[英]How to draw route between multiple points in Google Maps?
I have implemented google maps in my app and there are several points i need to mark on the map. I was able to mark them with markers but the problem i am facing is trying to draw the path between all those points.我已经在我的应用程序中实现了谷歌地图,我需要在 map 上标记几个点。我能够用标记标记它们,但我面临的问题是试图在所有这些点之间绘制路径。
I tried using polyline but it just draws a straight line between point A and point B. I also tried google maps directionsAPI and it shows all the possible routes between A and B.我尝试使用折线,但它只是在 A 点和 B 点之间画了一条直线。我还尝试了 google maps directionsAPI,它显示了 A 和 B 之间所有可能的路线。
My question is how do i draw proper route between point A -> point B -> point C -> point D. I want the route to start at point A then go through B and C and end at point C. ( I do not want to see alternate routes)我的问题是如何在 A 点 -> B 点 -> C 点 -> D 点之间绘制正确的路线。我希望路线从 A 点开始,然后通过 B 点 go 和 C,并在 C 点结束。(我不想看看替代路线)
Can anybody shed some light on how to do this?任何人都可以阐明如何做到这一点吗?
Here's simple and clean requet you can use这是您可以使用的简单干净的请求
https://maps.googleapis.com/maps/api/directions/json?origin=28.430348957506485,76.98648305807664&destination=28.599890024415032,77.39881368551802&waypoints=28.532347609852128,77.19007345114302|28.58602324471669,77.33358236227583&key=Your_API_KEY https://maps.googleapis.com/maps/api/directions/json?origin=28.430348957506485,76.98648305807664&destination=28.599890024415032,77.39881368551802&waypoints=28.532347609852128,77.19007345114302|28.58602324471669,77.33358236227583&key=Your_API_KEY
You need to pass one or more (list of) |您需要通过一个或多个(列表)| (pipe) separated lat longs (lat,longs) as waypoints to google's direction API.
(管道)分隔纬度经度(纬度,经度)作为指向谷歌方向 API 的航路点。 The overview polyline returned in response will contain a path from source to destination via all the way points you specified in your request.
作为响应返回的概览折线将包含一条从源到目的地的路径,通过您在请求中指定的所有路径点。
copying from Google's doc从 Google 的文档中复制
https://maps.googleapis.com/maps/api/directions/json?
origin=sydney,au&destination=perth,au
&waypoints=via:-37.81223%2C144.96254%7Cvia:-34.92788%2C138.60008
&key=YOUR_API_KEY
Read: https://developers.google.com/maps/documentation/directions/overview阅读: https://developers.google.com/maps/documentation/directions/overview
Scroll to waypoints section, its pretty straight forward:)滚动到航点部分,它非常简单:)
Suggestion: If you are passing a list of |建议:如果您传递的列表是 | (pipe) separated lat longs ensure to properly encode comma (,) to %2C between lat and long values and ensure not to leave any space between them.
(pipe) 分隔的 lat long 确保在 lat 和 long 值之间正确地将逗号 (,) 编码为 %2C,并确保它们之间不留任何空格。 Properly encode |
正确编码 | as well.
也是。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.