Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I'm trying to draw a rectangle on google map api v3 using the draw tool.I want the user to be able to :
1)get the rectangle bounds when the shape is complete.
2)update the bounds when the rectangle is dragged or reseized.

The (1) worked fine but i need some help on (2).
This is the code i used :

JavaScript
//----------on rectangle complete event
     google.maps.event.addDomListener(drawingManager, 'rectanglecomplete', function(rectangle) {
        //get the rectangle bounds
        document.getElementById("savedata").value =rectangle.getBounds();
   //hide draw tool
   drawingManager.setOptions({
       drawingControl: false
           });
   //disable draw tool
   drawingManager.setDrawingMode(null);
     });

Any help please?
Posted
Comments
Sergey Alexandrovich Kryukov 16-Apr-13 0:39am    
Please don't post non-answers as "solution". It can give you abuse reports which eventually may lead to cancellation of your CodeProject membership.
Comment on any posts, reply to available comments, or use "Improve question" (above).
Also, keep in mind that members only get notifications on the post sent in reply to there posts.
—SA

1 solution

Hi there,

Try this:

C#
//----------on rectangle complete event
     google.maps.event.addDomListener(drawingManager, 'rectanglecomplete', function(rectangle) {
        //get the rectangle bounds
        document.getElementById("savedata").value =rectangle.getBounds();
   //hide draw tool
   drawingManager.setOptions({
       drawingControl: false
           });
   //disable draw tool
   drawingManager.setDrawingMode(null);
     
     //Here the new code
     var rectangle = rectangle.overlay;

     //get new bounds
     google.maps.event.addListener(rectangle, "bounds_changed", function(event) {

	document.getElementById("savedata").value = rectangle.getBounds();

     });
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900