我採取的方法(n)的標記位置自動適應窗格迄今爲止一直:設置一個谷歌地圖視口的各個位置
function addMarker(query) {
var geocoder = new google.maps.Geocoder();
var afterGeocode = $.Deferred();
// Geocode 'query' which is the address of a location.
geocoder.geocode(
{ address: query },
function(results, status){
if(status === 'OK'){
afterGeocode.resolve(results); // Activate deferred.
}
}
);
afterGeocode.then(function(results){
var mOptions = {
position: results[0].geometry.location,
map: map
}
// Create and drop in marker.
var marker = new google.maps.Marker(mOptions);
marker.setAnimation(google.maps.Animation.DROP);
var current_bounds = map.getBounds(); // Get current bounds of map
// use the extend() function of the latlngbounds object
// to incorporate the location of the marker
var new_bounds = current_bounds.extend(results[0].geometry.location);
map.fitBounds(new_bounds); // fit the map to those bounds
});
}
我遇到的問題是,在地圖莫名無論新的標記是否適合當前的視口,縮小一定的量。
我在做什麼錯?
附錄
我添加日誌和一個額外的變量來捕捉地圖界限後過渡作出(new_new_bounds)
current_bounds = // Map bounds before anything is done.
{-112.39575760000002, 33.60691883366427},
{-112.39295444655761, 33.639099}
new_bounds = // From after the extend
{-112.39295444655761, 33.60691883366427},
{-112.39575760000002, 33.639099}
new_new_bounds = // From after the fitbounds
{-112.33942438265382, 33.588697452015374},
{-112.44928766390382, 33.657309727063996}
什麼是new_bounds說它的邊界在擴展之後? – 2011-05-13 21:09:49
更新了診斷程序。 – dclowd9901 2011-05-13 21:26:33
它看起來像從(x1,y1),(x2,y2) - >(x2,y1),(x1,y2)的邊界變化會引發問題。我不是100%,但那是我開始的地方。 – 2011-05-13 23:43:45