zoom/center to marker link in infowindow

398 views
Skip to first unread message

unxcolin

unread,
Aug 13, 2010, 1:04:26 PM8/13/10
to Google Maps JavaScript API v3
Hi,

In my createMarker function I can add setZoom and setCentre to the
click event like so, and it works great:

google.maps.event.addListener(marker, 'click', function() {
infobox.open(map, marker);
map.setZoom(12);
map.setCenter(latlng);
});

However I don't want to do this, I want this to occur on a link in the
infobox's content, but this code below won't work:

function zoomIn(latlng) {
map.setZoom(12);
map.setCenter(latlng);
}

content = "<a href=\"javascript:zoomIn(latlng)\">Zoom</a>";

Example page: http://bit.ly/d22gZo

Any ideas on why?

Thanks

geoco...@gmail.com

unread,
Aug 13, 2010, 1:25:32 PM8/13/10
to Google Maps JavaScript API v3
1. the page doesn't work at all in IE (you have a couple of "hanging
commas" one in the arrray that defines the markers, one in the
boxOptions object).

2. What value do you think latlng has?

-- Larry

geoco...@gmail.com

unread,
Aug 13, 2010, 1:29:40 PM8/13/10
to Google Maps JavaScript API v3
On Aug 13, 10:25 am, "geocode...@gmail.com" <geocode...@gmail.com>
wrote:
3. your map variable needs to be global to use it in your zoomIn
function.

  -- Larry

unxcolin

unread,
Aug 14, 2010, 4:24:26 AM8/14/10
to Google Maps JavaScript API v3
Aha, okay making the map global fixes the issue and the function now
works! Thank you!

However you're right, latlng isn't working how I imagined it to be and
I can't figure out why. setCenter isn't working at all within the
function - I just thought it took the latlng variable in the form (x,
y)? This seems to work just fine when I trigger it on click event but
not from within this function!

Thanks for spotting the IE issue, haven't tested with it yet but have
now removed the two hanging commas.


On Aug 13, 6:29 pm, "geocode...@gmail.com" <geocode...@gmail.com>

unxcolin

unread,
Aug 14, 2010, 12:28:58 PM8/14/10
to Google Maps JavaScript API v3
Sorted this by changing the function to:

function zoomIn(lat, lng) {
map.setZoom(12);
var myLatLng = new google.maps.LatLng(lat, lng);
map.setCenter(myLatLng);
}

Thanks
Reply all
Reply to author
Forward
0 new messages