Set Center

1,287 views
Skip to first unread message

capeck

unread,
Oct 15, 2009, 12:17:35 PM10/15/09
to Google Maps JavaScript API v3
HI,
I am having some issues using map.setCenter().
I have a "jump to" select option input that re-centers the map. This
seems to work fine on FF, but not on IE (I'm testing with IE7).

Code example:
latlng = new google.maps.LatLng(42.74, -110.74);
myMap.setCenter(latlng);
myMap.setZoom(10);

The next scenario is trying to put a "Zoom Here" in the info window
for a specific point. In my function that builds up the infowindow, I
pass in a latlng and add to the infowindow the following:

+ "<a href=\"javascript:myMap.setCenter" + glatlng + ";\">Zoom Here</
a>";

This gives me the following error in Firebug and in IE:
Invalid value for property <center>: 43.525433

I assume I'm not building up the javascript correctly, but glatlng is
a google.maps.LatLng object.


Thanks for your help.







I get the following

Ben Appleton

unread,
Oct 15, 2009, 1:38:24 PM10/15/09
to google-map...@googlegroups.com
Hi,

On Thu, Oct 15, 2009 at 9:17 AM, capeck <carol...@gmail.com> wrote:

HI,
I am having some issues using map.setCenter().
I have a "jump to" select option input that re-centers the map.  This
seems to work fine on FF, but not on IE (I'm testing with IE7).

Code example:
latlng = new google.maps.LatLng(42.74, -110.74);
myMap.setCenter(latlng);
myMap.setZoom(10);

The next scenario is trying to put a "Zoom Here" in the info window
for a specific point. In my function that builds up the infowindow, I
pass in a latlng and add to the infowindow the following:

 + "<a href=\"javascript:myMap.setCenter" + glatlng + ";\">Zoom Here</
a>";

This gives me the following error in Firebug and in IE:
Invalid value for property <center>: 43.525433

The problem is that
    "<a href=\"javascript:myMap.setCenter" + glatlng + ";\">Zoom Here</a>" 
becomes eg.
    "<a href=\"javascript:myMap.setCenter(43.525433, 0);\">Zoom Here</a>" 
myMap.setCenter then correctly asserts that 43.525433 is not a LatLng object.

Instead you probably want to write
    "<a href=\"javascript:myMap.setCenter(glatlng);\">Zoom Here</a>" 
Reply all
Reply to author
Forward
0 new messages