我正在为我的位置服务应用程序使用谷歌地图和谷歌地理编码服务。我使用 Google 地理编码服务将地址转换为 lat/lng 位置。我的问题是如何像 maps.google.com 那样自动为某个地址找到合适的缩放比例。
例如,当我在 maps.google.com(例如Cisitu Baru, Bandung
)中搜索街道时,它会以较小的缩放比例显示街道。当我搜索一个区域(例如Bandung
)时,它会显示更大的缩放。以及更大的省缩放比例(例如Jawa Barat
/ West Java
),等等。
我都试过了
var geocoder = new google.maps.Geocoder();
geocoder.geocode( {
'address': someAddress
}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
console.dir(results);
//cut
map.panToBounds(results[0].geometry.bounds); //setting bound
//cut
}
});
和
//cut
map.panToBounds(results[0].geometry.viewports); //setting bound
//cut
(老实说,我仍然不知道 code.google.com/apis/maps/documentation/javascript/geocoding.html 之间有什么区别bounds
以及viewport
它们的用途是什么)
但两者仍然没有以适当的缩放比例显示地图。
现在,我使用这样的小技巧
var tabZoom = {
street_address: 15,
route: 15,
sublocality: 14,
locality: 13,
country: 10
};
//cut
map.setCenter(results[0].geometry.location);
if (tabZoom[results[0].types[0]] != undefined){
map.setZoom(tabZoom[results[0].types[0]]);
} else {
map.zetZoom(10);
}
//cut
还有其他解决方案吗?(或者我还不知道的来自 Google Map API 的任何东西?)
谢谢!