Google Maps v3 Move Polygon

UPDATE 2018.03.07: The issue requesting to have this in the core of Google Maps got marked as fixed … unfortunately I cannot find this change back in the documentation, so I’m not too sure if it’s actually fixed or not. Will keep tracking it.

Since Google Maps v3.11 (*) it’s possible to move around a google.maps.Polygon by using the mouse (if the draggable property is set to truesee example here). Unfortunately the API does not allow us to move that Polygon programatically.

google.maps.Polygon.moveTo() is a Google Maps extension enabling just that: it allows one to programmatically move a google.maps.Polygon on the map without any user/mouse interaction. The script works with both geodesic (polygons that follow the curvature of the earth) and non-geodesic (straight) polygons.

google-maps-move-polygon

In the screenshot above, the red polygon is the original one, and the green one is the one that’s been moved using google.maps.Polygon.moveTo(). The distortion is normal, due to the Mercator Projection

google.maps.Polygon.moveTo() →

(*) The current stable version of Google Maps still is 3.10. For now (until 3.11 is the stable one), you can include the experimental 3.11 version by referencing http://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false

Elsewhere , , ,

10 Responses to Google Maps v3 Move Polygon

  1. Collin Green says:

    This is exactly what I needed – good timing posting it! Thank you very much!

  2. Collin Green says:

    Heads up — since this script replaces the paths you’ll need to re-add any path events you have. I’ll work on a pull request for this at some point.

    • Bramus! says:

      Hi Collin,

      That indeed is the case (didn’t take it into account when developing the plugin). Looking forward to the pull request.

      Regards,
      Bram.

  3. Pingback: Google Maps v3 Drag Polygon | Bram.us

  4. Pingback: Mercator Puzzle Redux | Bram.us

  5. Cyril B says:

    I need to move several polygon, you method is exactly what I’m looking for!
    You did it 5 years ago, is it still the right way to do it?

    thanks,
    Cyril

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.