/ Published in: JavaScript
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
// init // Plot two markers to represent the Rectangle's bounds. marker1 = new google.maps.Marker({ map: map, position: new google.maps.LatLng(65, -10), draggable: true, title: 'Drag me!' }); marker2 = new google.maps.Marker({ map: map, position: new google.maps.LatLng(71, 10), draggable: true, title: 'Drag me!' }); // Allow user to drag each marker to resize the size of the Rectangle. google.maps.event.addListener(marker1, 'drag', redraw); google.maps.event.addListener(marker2, 'drag', redraw); // Create a new Rectangle overlay and place it on the map. Size // will be determined by the LatLngBounds based on the two Marker // positions. rectangle = new google.maps.Rectangle({ map: map }); redraw(); function redraw() { var latLngBounds = new google.maps.LatLngBounds( marker1.getPosition(), marker2.getPosition() ); rectangle.setBounds(latLngBounds); //console.log(marker1.getPosition()+","+marker2.getPosition()); }