Reducing number of points in Directions Service Polyline?

666 views
Skip to first unread message

Evan Rolfe

unread,
Oct 11, 2011, 9:22:47 AM10/11/11
to Google Maps JavaScript API v3
Hi all, is there any way I can reduce the number of points in a
polyline obtained from the Directions Service api?

I'm coding an application that should draw a route from the user's
address to another address and create a printer friendly version of
the map with the route. In order to get a printer friendly version I'm
creating a static map with the polyline obtained from the route from
directions service.

The only problem I'm having now is that most routes seem to have
encoded (yes i'm encoding the polyline points to shorten the url)
strings which are longer than 2048 characters so cannot be passed to
google static maps api via a url, this is why i'm trying to reduce the
number of points in the directions route and hence reduce the
accuracy.

Or if anybody has a better/more elegant solution please let me know!
Thanks!

Ben Appleton

unread,
Oct 11, 2011, 12:52:11 PM10/11/11
to google-map...@googlegroups.com
Hi Evan,

The directions service result contains a field "overview_path":
This is pre-simplified to fit in a static map URL.

Cheers
Ben


--
You received this message because you are subscribed to the Google Groups "Google Maps JavaScript API v3" group.
To post to this group, send email to google-map...@googlegroups.com.
To unsubscribe from this group, send email to google-maps-js-a...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-maps-js-api-v3?hl=en.


Berry Ratliff

unread,
Oct 11, 2011, 2:40:56 PM10/11/11
to Google Maps JavaScript API v3
> Or if anybody has a better/more elegant solution please let me know!

I believe it is legal. Ben, please correct me if I am wrong.

Your printer driver may not be able to superimpose two identically
positioned DIVs (one IMG / one CANVAS) but it ought to be able to
print a single composite CANVAS element. You could use the
"drawImage" method to transfer your static map image to a CANVAS
element. You could use the "moveTo" & "lineTo" methods to draw your
polys on the same CANVAS element. You will have to apply Mercator
projection conversions from Lat/Lon coordinates to X/Y pixel
positions.

The file:

http://home.provide.net/~bratliff/adjust.js

contains conversion functions.

Berry Ratliff

unread,
Oct 12, 2011, 12:15:09 PM10/12/11
to Google Maps JavaScript API v3
I have built a simple demo:

http://home.provide.net/~bratliff/coast/

Point reduction does not improve performance. It consumes more
resources than it saves. If the same polys will be used again, point
reduction will help. If a point is very near the interpolation line
connecting the two adjacent points, the intermediate point can be
dropped.

Chris Broadfoot

unread,
Oct 12, 2011, 11:36:27 PM10/12/11
to google-map...@googlegroups.com
Nice work, Berry.

The browser should be able to composite the images when printing (i.e. canvas over another image, placed with CSS), so you shouldn't *need* to draw the static map onto the canvas element.

Also, for printing, I'd recommend using PNG instead of JPG.

Berry Ratliff

unread,
Oct 13, 2011, 9:44:41 AM10/13/11
to Google Maps JavaScript API v3
On Oct 13, 4:36 am, Chris Broadfoot <c...@google.com> wrote:
> Nice work, Berry.
>
> The browser should be able to composite the images when printing (i.e.
> canvas over another image, placed with CSS), so you shouldn't *need* to draw
> the static map onto the canvas element.
>
> Also, for printing, I'd recommend using PNG instead of JPG.
>
> Chris

Hi Chris,

What about color blending & alpha blending of overlapped IMG & CANVAS
elements ? Can standard printer drivers handle it ?

P.S.

I did not mean point reduction is not important. I did mean it is
overkill for a single usage with a static map.

Berry Ratliff

unread,
Oct 13, 2011, 11:10:15 AM10/13/11
to Google Maps JavaScript API v3
I have added markers along the path plus some other improvements.
Reply all
Reply to author
Forward
0 new messages