0
我在使用map.fitbounds時遇到了一些問題。我在地圖上通過兩點,並使用方向服務。我使用map.fitbounds到中心的兩個特定點之間的地圖,遇到了其中地圖實際上最終顯示了這個代碼特定部分的世界觀問題:Google Maps API v3 JS map.fitbounds
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
window.addEvent('domready', function() {
initialize();
});
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
var currentDirections = null;
var clat = 52.03574;
var clng = 0.58363;
var dlat = 51.08577;
var dlng = -1.31712;
function initialize()
{
var mOptions = {
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map($("mapCanvas"), mOptions);
directionsDisplay = new google.maps.DirectionsRenderer({
'map': map,
'preserveViewport': true,
'draggable': true//,
//'suppressMarkers': true
});
directionsDisplay.setPanel($("directions_panel"));
google.maps.event.addListener(directionsDisplay, 'directions_changed', function() {
currentDirections = directionsDisplay.getDirections();
});
var start = 'Little Yeldham, Halstead, Essex CO9 4JZ, UK';
var end = 'Winchester, Hampshire SO21, UK';
var request = {
origin: start,
destination: end,
travelMode: google.maps.DirectionsTravelMode.DRIVING,
unitSystem: google.maps.DirectionsUnitSystem.IMPERIAL
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);
}
});
var collectionPoint = new google.maps.LatLng(clat, clng);
var deliveryPoint = new google.maps.LatLng(dlat, dlng);
var bounds = new google.maps.LatLngBounds(collectionPoint, deliveryPoint);
map.fitBounds(bounds);
}
</script>
誰能幫助或點我在正確的方向如何簡單地顯示正確的顯示距離?