我创建了一个 javascript 程序,它根据以下代码在谷歌地图中选择一个矩形:
function initMap() {
var latlng = new google.maps.LatLng(43, -89);
var settings = {
zoom: 4,
center: latlng,
mapTypeControl: true,
mapTypeControlOptions: {
style: google.maps.MapTypeControlStyle.DROPDOWN_MENU
},
navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.SMALL
},
mapTypeId: google.maps.MapTypeId.SATELLITE
}
var mapElem = $("#map-canvas");
map = new google.maps.Map(mapElem[0], settings);
rect = new google.maps.Rectangle({
map: map
});
google.maps.event.addListener(map, 'mousedown', function(mEvent) {
map.draggable = false;
latlng1 = mEvent.latLng;
dragging = true;
pos1 = mEvent.pixel;
});
google.maps.event.addListener(map, 'mousemove', function(mEvent) {
latlng2 = mEvent.latLng;
showRect();
});
/*
google.maps.event.addListener(map, 'mouseup', function(mEvent) {
map.draggable = true;
dragging = false;
});
*/
google.maps.event.addListener(rect, 'mouseup', function(data){
map.draggable = true;
dragging = false;
var lat1 = latlng1.lat();
var lat2 = latlng2.lat();
var minLat = lat1<lat2?lat1:lat2;
var maxLat = lat1<lat2?lat2:lat1;
var lng1 = latlng1.lng();
var lng2 = latlng2.lng();
var minLng = lng1<lng2?lng1:lng2;
var maxLng = lng1<lng2?lng2:lng1;
alert('Datbase query for the following bounds:\n\nlat: ' + minLat + ' to ' + maxLat+ '\n\nlng: ' + minLng + ' to ' + maxLng);
});
}
function showRect() {
if(dragging){
if (rect === undefined) {
rect = new google.maps.Rectangle({
map: map
});
}
var latLngBounds = new google.maps.LatLngBounds(latlng1, latlng2);
rect.setBounds(latLngBounds);
}
}
不幸的是,从今天开始,该代码不再起作用。为什么它不再起作用了?