2

我有一个左侧菜单栏,当有人点击链接时,它会跳转到地图上的标记位置。这工作正常。

但是,我想更新它,以便当他们单击左侧栏中的链接时,地图以标记为中心并缩放到一定水平。但这不能正常工作。

我在 Firebug 中收到的错误是:

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

代码:

<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);
  });
4

1 回答 1

2

map.setCenter()并且map.setZoom()需要特定的参数,并且文档对其语法并没有真正的帮助。

map.setCenter()需要一个LatLng对象:

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

map.setZoom()取一个简单的整数:例如map.setZoom(16);

冒号在对象定义中有特殊用途,但在这里没有位置。这就是导致您的错误消息的原因。

附加问题:这里的 latLng 是什么...?
map.setCenter(latlng:latLng);

这需要在某个地方定义。也许您希望地图以标记为中心?

map.setCenter(this.getPosition());

于 2012-06-04T17:30:09.947 回答