多數民衆贊成我現在...
function extendRegion(marker, drawing){
marker_lat = marker.getPosition().lat();
marker_lng = marker.getPosition().lng();
if(drawing.type == google.maps.drawing.OverlayType.CIRCLE){
var path = [marker.getPosition(), drawing.overlay.getCenter()];
var length = google.maps.geometry.spherical.computeDistanceBetween(path[0], path[1]);
if(length>drawing.overlay.getRadius()){
consloe.log('The Marker was outside the drawing, it is extended now.');
drawing.overlay.setRadius(length);
}
}
else if(drawing.type == google.maps.drawing.OverlayType.RECTANGLE){
ne_lat = drawing.overlay.getBounds().getNorthEast().lat();
ne_lng = drawing.overlay.getBounds().getNorthEast().lng();
sw_lat = drawing.overlay.getBounds().getSouthWest().lat();
sw_lng = drawing.overlay.getBounds().getSouthWest().lng();
var error=0;
if(marker_lat<sw_lat){
sw_lat = marker_lat;
error=1;
}
if(marker_lat>ne_lat){
ne_lat = marker_lat;
error=1;
}
if(marker_lng<sw_lng){
sw_lng = marker_lng;
error=1;
}
if(marker_lng>ne_lng){
ne_lng = marker_lng;
error=1;
}
if(error) {
console.log('The Marker was outside the drawing, it is extended now.');
drawing.overlay.setBounds({north: ne_lat, south: sw_lat, east: ne_lng, west: sw_lng});
}
}
}
閱讀:http://stackoverflow.com/questions/37997093/trying-to-get-google-map-with-user-set-radius –