我这里有一段代码在地图上绘制一组路径。我试图让地图缩放和居中,以便所有路径都可见,但我什么也做不了。这是我开始之前的代码:
var points = new Array();
var pointsData = [];
var pointsData = $('#master-' + r + ' > #route-data').html();
if (pointsData != '')
{
var pointsArray = JSON.parse(pointsData);
for (var p=0; p<pointsArray.length; p++) {
points.push(new google.maps.LatLng(pointsArray[p][0], pointsArray[p][1]));
}
$.OverMap.drawRoute(points);
}
else $.OverMap.drawDirections({preserveViewport:false});
在摆弄它之后:
map = this.map.map;
map.fitBounds(this.map.bounds);
zoomChangeBoundsListener =
google.maps.event.addListenerOnce(map, 'bounds_changed', function(event) {
if (this.getZoom()){
this.setZoom(16);
}
});
setTimeout(function(){google.maps.event.removeListener(zoomChangeBoundsListener)}, 2000);
// Draw route
var bounds = new google.maps.LatLngBounds();
var points = new Array();
var pointsData = [];
var pointsData = $('#master-' + r + ' > #route-data').html();
if (pointsData != '')
{
var pointsArray = JSON.parse(pointsData);
for (var p=0; p<pointsArray.length; p++) {
points.push(new google.maps.LatLng(pointsArray[p][0], pointsArray[p][1]));
bounds.extend(pointsArray[p][0], pointsArray[p][1]);
}
$.OverMap.drawRoute(points);
}
else $.OverMap.drawDirections({preserveViewport:false});
谁能指出我哪里出错了?