I got it figured out and took the approach I mentioned below and it
seems to look ok...
var poly = dirn.getPolyline();
var getNthVertex = Math.ceil(poly.getVertexCount()/150); // get every
nTh Vertice (limiting to 150 total)
var loops = Math.floor(poly.getVertexCount()/getNthVertex); // how
many loops to do to cover the whole poly
var llArray = new Array(); // array to hold the points
var curVertex = 0;
for (var i=0; i < loops; i++) {
llArray.push(poly.getVertex(curVertex).lat());
llArray.push(poly.getVertex(curVertex).lng());
curVertex = curVertex + getNthVertex;
}
llArray.push(poly.getVertex(poly.getVertexCount() - 1).lat());
llArray.push(poly.getVertex(poly.getVertexCount() - 1).lng());
staticMapURL += '&path=enc:' + gp_compressShapes(llArray,5);
On Mar 1, 2:22 pm, Scott H <[email protected]> wrote:
> I am working on a printable version of a route and have a routine that
> builds a Static Map. It "works", but has a problem when there are too
> many vertices in the Polyline. The URL becomes to large for the
> Static Map API.
>
> My code for gp_compressShapes() works to encode the line fine.
>
> My code is below.
>
> // dirn is the GDirections object
> var poly = dirn.getPolyline();
> var vertCount = poly.getVertexCount();
> var llArray = new Array();
> for (var i=0; i < vertCount; i++) {
> llArray.push(poly.getVertex(i).lat());
> llArray.push(poly.getVertex(i).lng());}
>
> var encPoly = gp_compressShapes(llArray,5);
> staticMapURL += '&path=enc:' + encPoly;
>
> *** My main question is whether there is a good way to use a subset of
> the vertices in the Polyline to still give it the effect of the route
> path, but not all the detail.
>
> An encoded LatLng seems to be about 10 characters on average. Since
> URLs cannot be too long, I am thinking I'd work with an arbitrary
> number of the Vertices (e.g. 200) and take every nth one so I have <=
> 200 total and then encode that. Worst case is that this gives me a
> less detailed polyline, but it on the same path.
>
> Thoughts?
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.