Directions Polyline & Viewport issue

117 views
Skip to first unread message

pete

unread,
Jan 28, 2010, 12:15:28 AM1/28/10
to Google Maps JavaScript API v3
Hi there,

I have discovered an issue which causes a point from the directions
result to be off the map.

Just to clarify, I don't have preserveViewport set to true.
With almost all addresses the map re-zooms correctly to fit in both
Point A and Point B along with the polyline.

I have put together a simplified demo of the issue I am witnessing in
my application here:

http://taledo.com.au/demos/directions.htm

Upon visiting, please hit "find" and you will see that Point B is off
the map.

Any ideas/insights would be greatly appreciated

Chad Killingsworth

unread,
Jan 28, 2010, 8:10:38 AM1/28/10
to Google Maps JavaScript API v3
Actually technically Point B is on the map - barely. Point B's marker
on the other hand ...

You are bringing up a similar issue as Erich in point 1 of
http://groups.google.com/group/google-maps-js-api-v3/browse_thread/thread/f6ae522cac602e7c

Chad Killingsworth

pete

unread,
Jan 28, 2010, 6:31:43 PM1/28/10
to Google Maps JavaScript API v3
Indeed, I should have specified that the base of the marker is "on"
the map, but not the marker itself.

So seeing as the link you provided has no response either, is one to
assume there is no work-around for this issue?

Thx


On Jan 29, 12:10 am, Chad Killingsworth


<chadkillingswo...@missouristate.edu> wrote:
> Actually technically Point B is on the map - barely. Point B's marker
> on the other hand ...
>

> You are bringing up a similar issue as Erich in point 1 ofhttp://groups.google.com/group/google-maps-js-api-v3/browse_thread/th...

Esa

unread,
Jan 29, 2010, 5:17:21 AM1/29/10
to Google Maps JavaScript API v3

On Jan 29, 1:31 am, pete <petejun...@gmail.com> wrote:

> So seeing as the link you provided has no response either, is one to
> assume there is no work-around for this issue?
>


map.panBy(0,-20); // or:
map.setZoom(map.getZoom()-1);


But. First you should test if a marker is too close to map border. See
Pamela's technique in custom info window script.
http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/infowindow-custom.html
You need degrees/pixel ratios. She calculates those:

map.getBounds().toSpan().lat() / map.getDiv().offsetHeight;
map.getBounds().toSpan().lng() / map.getDiv().offsetWidth;

Now you can do some more calculation to get how close the marker is to
the border.

Second problem is how to perform zoomOut or panning. The asynchronous
nature of fitBounds() makes that your operation is presumably
overriden by DirectionsRenderer.

The brand new addListenerOnce() offers a solution with 'idle' event.
It is triggered only once.

Try putting inside the callback function of route(). (Just after
directionsDisplay.setDirections(response);) Even without any border
testing:


google.maps.event.addListenerOnce(map, 'idle', function(){
map.panBy(0,-20);
});

pete

unread,
Jan 31, 2010, 4:35:20 PM1/31/10
to Google Maps JavaScript API v3
Thanks for the reply. I did find a way to do this (not as elegant as
your example), however I was wondering if this was an issue itself.
Not ever having used API 2, I wasn't sure if this was an API 3 problem
or a math problem :)

Any insight into this?

On Jan 29, 9:17 pm, Esa <esa.ilm...@gmail.com> wrote:
> On Jan 29, 1:31 am, pete <petejun...@gmail.com> wrote:
>
> > So seeing as the link you provided has no response either, is one to
> > assume there is no work-around for this issue?
>
>     map.panBy(0,-20);  // or:
>     map.setZoom(map.getZoom()-1);
>
> But. First you should test if a marker is too close to map border. See

> Pamela's technique in custom info window script.http://gmaps-samples-v3.googlecode.com/svn/trunk/infowindow_custom/in...

Reply all
Reply to author
Forward
0 new messages