panTo() functionality example?

3,282 views
Skip to first unread message

Mike

unread,
Dec 1, 2009, 9:39:15 AM12/1/09
to Google Maps JavaScript API v3
Hi, I looked around the v3 site, but couldn't find an example of how
to implement the panTo functionality. I am developing locally, so I
don't have a link to share.

What I am trying to do is this: In a separate div, I would like a user
to click a link, and the map move to that point.

Thanks in advance for any help.
-Mike

Esa

unread,
Dec 1, 2009, 6:06:39 PM12/1/09
to Google Maps JavaScript API v3
Your map and panPoint must be global variables (defined outside
intialize()).

var panPoint = new google.maps.LatLng(number, number);

In html:

<a href="javascript:map.panTo(panPoint)">Pan</a>


Mike

unread,
Dec 1, 2009, 8:52:49 PM12/1/09
to Google Maps JavaScript API v3
Thanks for responding Esa, I tried it and it is outside the initialize
function, but I get a JS error is Firebug:

map is not defined
javascript:map.panTo(panPoint)()

I am going to play around with it, but if you have any quick thoughts,
I'd like to hear them.

Thanks again,
Mike

Chad Killingsworth

unread,
Dec 2, 2009, 12:15:33 AM12/2/09
to Google Maps JavaScript API v3
Here's an example. Notice that map is defined outside the initialize
function:

http://search.missouristate.edu/map/mobile/examples/panto.htm

Chad Killingsworth

Mike

unread,
Dec 2, 2009, 8:08:37 PM12/2/09
to Google Maps JavaScript API v3
Chad, outstanding! From your example I see what I was doing wrong &
got my code to work correctly.
Thanks for the help,
Mike

On Dec 2, 12:15 am, Chad Killingsworth
Reply all
Reply to author
Forward
0 new messages