google maps API v3 - how to draw dynamic polygons/polylines?

后端 未结 6 797
猫巷女王i
猫巷女王i 2020-12-07 15:54

I have 4 days of experience with Google Maps Javascript API and i find their documentation and information sharing confusing at best.

Does anyone have experience or

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 16:34

    Take a look at this example, from the Maps API v3 examples page:

    http://code.google.com/apis/maps/documentation/javascript/examples/polyline-complex.html

    The code listens to clicks on the map, and on each click adds an extra lat/lng pair into the array of a polyline. This results in a polyline which joins each clicked point.

    Extending this to polygon should be relatively simple. At some point you will need to close the polygon. You could do this by listening to a click on the polygon or a marker (indicating an intersection) or by having a button the user can click, and setting the polygon to autoclose.

提交回复
热议问题