user1424532
user1424532

Reputation: 95

map.setcenter & map.setzoom not working properly

I have a left side menu bar which when someone clicks on the a link, it jumps to the marker location on the map. This works fine.

But, I'd like to update this so that as they click the link in the left-side bar, the map centers on the marker and zooms to a certain level. But this isn't working proplerly.

The error I'm receiving in Firebug is:

missing ) after argument list
map.setCenter(latlng:latLng);

Code:

<div id="LeftArea" style="width: 220px; float: left; border-bottom: 1px solid #dedede; padding: 5px 0 5px 0;">
    <div style="color: #a41d21;font-size: 13px; font-weight: bold;">
        <script language="javascript" type="text/javascript">
            document.write('<a href="javascript:myclick(' + (i) + ')">' + '[[Title]]' + '<\/a><br>');
        </script>
    </div>
    <div>
        [[Address]]<br />
        [[City]], [[State]] [[Zip]]
    </div>
</div>

myclick = function(i) {
  google.maps.event.trigger(gmarkers[i], "click");
}

// Associate the markers with the links in the side bar.
  gmarkers[i] = marker;

// Display the info window when someone clicks on a marker or it's associated side bar link.
  google.maps.event.addListener(marker, 'click', function () {
    map.setCenter(latlng:latLng);
    map.setzoom(zoom: 16);
    InfoWindow.setContent(this.html);
    InfoWindow.open(map, this);
  });

Upvotes: 2

Views: 6535

Answers (1)

Andrew Leach
Andrew Leach

Reputation: 12973

map.setCenter() and map.setZoom() need specific arguments, and the documentation doesn't really help with its syntax.

map.setCenter() requires a LatLng object:

myLatLng=  new google.maps.LatLng(0,0);
map.setCenter(myLatLng);

map.setZoom() takes a simple integer: for example map.setZoom(16);

Colons have a particular use in object definitions, but have no place here. This is what is causing your error message.

Additional issue: what is latLng here...?
map.setCenter(latlng:latLng);

That will need to be defined somewhere. Perhaps you want the map centred on the marker?

map.setCenter(this.getPosition());

Upvotes: 2

Related Questions