Google 地图 API v3 地理编码器视口
当我输入一个位置(城市或国家)并且信息窗口打开时,以下代码将仅查找打开的信息窗口区域内的位置:
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
我希望得到一些帮助 - 谢谢!
when I enter a location (city or country) and an infowindow is open the following code will only find locations within the area of the open infowindow:
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);
}
});
}
I want to zoom to the location viewport WITHOUT the fitBounds
This kind of works:
map.setZoom(13);
But I don't want to specify the zoom level
Here's a link from the latter code: http://www.hostelbars.com/map_test_v3_3.html
I'd appreciate some help - thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许您想将地理编码限制在可见地图的范围内,而不是打开的信息窗口?
您需要在请求中告诉地理编码器您想要的范围,而不是在处理结果时。
请参阅 http://code.google.com/apis/maps /documentation/javascript/reference.html#GeocoderRequest
将 geocoderRequest 中的边界设置为 map.getBounds()。
Perhaps you want to constrain the geocoding to the bounds of the visible map, rather than the open infowindow?
You need to tell the geocoder about your desired bounds in the request not when handling the result.
Refer to http://code.google.com/apis/maps/documentation/javascript/reference.html#GeocoderRequest
Set the bounds in the geocoderRequest to map.getBounds().