Draw a percentage of a route between 2 points on map with Google Maps or other Map API
Assume point A is San Francisco, CA and Point B is New York, NY.
Using either Google Maps or another online mapping API, I'd like to be able to get the default driving route, then only draw a percentage of it on the map. So, if I only wanted to draw 50% of t开发者_开发问答he route, it would end somewhere in Nebraska.
I've been unable to find any way to do this out of the box, so any API usages or clever ways to achieve it would be appreciated.
Thanks in advance!
You can make use of the polyline received at the end of the Google direction response API. This has a set of encoded points that let you draw a path over a static map. See Google maps documentation for details. It is very clearly written and intuitive.
As for the 50% thing, you can check the time of the journey and maybe, at near half time, set the destination to that particular location, and make a second query for the direction response, with the new destination. Alternatively, you can choose to do the processing at your end, but that is extra hassle you can ignore by offshoring the load on Google servers.
精彩评论