1

当我输入一个位置(城市或国家)并且信息窗口打开时,以下代码将仅在打开的信息窗口区域内找到位置:

function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
  if (status == google.maps.GeocoderStatus.OK) {
    map.setCenter(results[0].geometry.location);
    map.fitBounds(results[0].geometry.viewport);
         } else {
    alert("Sorry, we couldn't find the location for the following reason: " + status);
  }
});

}

我想在没有 fitBounds 的情况下缩放到位置视口

这种作品:

map.setZoom(13);

但我不想指定缩放级别

这是后一个代码的链接:http: //www.hostelbars.com/map_test_v3_3.html

我会很感激一些帮助 - 谢谢!

4

1 回答 1

0

也许您想将地理编码限制在可见地图的范围内,而不是打开的信息窗口?

您需要在处理结果时告诉地理编码器您想要的请求边界,而不是。

请参阅http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest

将 geocoderRequest 中的边界设置为 map.getBounds()。

于 2012-01-03T23:59:53.503 回答