Google Maps v3: need multiple draggable markers to update HTML input fields

前端 未结 2 1087
悲哀的现实
悲哀的现实 2021-01-03 01:28

I\'m working on a project using Google Maps v3 that will allow users to drag and drop randomly placed markers (quantity, coordinates, and labels generated with php).

2条回答
  •  醉酒成梦
    2021-01-03 02:00

    Well one of the beautiful things about JavaScript is that you can assign objects fields on the fly. One thing you could do would give each marker a name or an id. To do that you simply say:

    marker.id = whatever;
    

    Then you can get the value of that like you would any property by calling marker.id;

    That is probably the most efficient way of giving them unique id's. In your eventhandler for the dragend you could then just do and if-then-else to check which marker it was and update the related input fields.

提交回复
热议问题