Google maps V3 custom route via given lat/lng points
Hey there, I have a GPS module in my car and it saves every 30 seconds my position and then it exports those points of the entire travel. So when I drive about 5 hours, it has about 600 waypoints stored. Now I want to show my trip in google map. One of the soulutions is to generate a .kml file and then draw a polyline inside the map. But because it stores position every 30 seconds, the line is often "off-road". Is there 开发者_开发百科a way google will draw this way exactly on the road? the route() function is useless because of limit of waypoints (i think 8).
Any ideas?
I've been testing the exact same thing today and have come to the conclusion that the frequency of acquiring the co-ordinates should be a function of distance covered rather than being dependent on time. I have kept the threshold distance as 10m and have been able to resolve most of the instances of the lines going off the road.
Er just saw that this question was asked some time ago >_> maybe it will help someone anyway.
If you have enough time you could preprocess the data. Method won't work if you don't have your own server - really rough outline of my thoughts:
var path = [];
var index = 0;
function getRoute() {
thisRoute = getRoute(yourPoints[index], yourPoints[index+=10]);
index+=10;
for(each step in thisRoute)
path.append(step);
if (index < yourPoints.length)
setTimeout(getRoute(), 1000); // or however long it takes for you to be able to get directions again
else
store path in local file which is used later on when you need the full path
}
So to do this you need some way to store the path - I would use my own server and PHP, or there may be other ways that I'm not aware of. When I want to show the path I would retrieve it again using PHP, then draw it with polylines. There are examples around the place for the path.append(step)
. I'm sure there are better ways to do it (maybe python rather than JS) but this is the general approach I would take.
精彩评论