v3 polylines truncate "leaf nodes" in routes.

23 views
Skip to first unread message

Robert Lipe

unread,
Oct 1, 2009, 1:09:49 AM10/1/09
to Google Maps JavaScript API v3
Hello, Google Map Gurus.

I'd sort of fallen off the boat of the API and wound up implementing a
Map that that relied on Polylines before the blog post announced they
were added. I'd been beating my head on the wall trying to figure
out why I was losing key vertices in a polyline, but I'm now
suspecting the problem isn't entirely mine.


I have a polyline that consists of almost 800 points. (From v1 api, I
know this is too many, but the map in question needs to be the
"before" in a "before and after" comparison once we simplify the
points. To Google's credit, 800 points in a polyline doesn't melt
the browser like it did back in the Old Days.) These are points
gathered from a GPS on a school bus in a rural area. School busses
in rural areas drive to where the kids are and they often turn
around.

I'm seeing a large number of these "turnaround" roads shortened or
dropped completely when I pull them into the map. I've put a screen
capture of an affected area up temporarily at http://www.gpsbabel.org/tmp/Picture%2055.png

The code in question is blindingly dumb. It's just a plain array of
vertices:

var pathCoords = [[30.705786, -96.374112],
[30.706147, -96.374148],
[30.706077, -96.374136],
[30.706073, -96.374152],
[30.706065, -96.374184],
[30.705878, -96.374093],
[ continues for completely too long ]

and I just added the markers (cut and pasted from the examples) to
"prove" that the GPS tracks captured what I thought they captured.
The key function is the pretty obvious:

function loadup(a, path, map) {
for (i = 0; i < a.length; i++) {
lat = a[i][0];
lng = a[i][1];
pnt = new google.maps.LatLng(lat, lng);
path.insertAt(path.length, pnt)
// for debugging, add a marker.
var marker = new google.maps.Marker({
position: pnt,
map: map,
title:"Hello World!"
});
bbox.extend(pnt);
}
}

I suspect that the polyline code is simplifying the polyline and not
accounting for the "doubleback" case when computing maximum
crosstrack error. It may be data specific, but I have several
occurrences of it in only two GPS tracks, so it's not like it's
extremely hard to trigger on this type of data.

If a Google developer hasn't branded me a bozo at this point and isn't
smacking his or her (potentially multicolored) forehead at this point
and needs to see the full Javascript with data, please contact me
privately.

Ben Appleton

unread,
Oct 1, 2009, 2:09:48 AM10/1/09
to google-map...@googlegroups.com
Please do publish a failing page and link here. There's little we can
do without seeing the bug.
Reply all
Reply to author
Forward
0 new messages