Get marker id in google maps

前端 未结 2 1216
北恋
北恋 2020-12-17 03:59

I want to pass related marker id by clicking marker on google map. I am using marker.getId() function to retrieve marker id. But the marker id is not passing along with url.

2条回答
  •  醉梦人生
    2020-12-17 04:46

    the best way to do this is add a metadata to marker

    var marker = new google.maps.Marker(markerOptions);
    marker.metadata = {type: "point", id: 1};
    

    if you have so many marker push the marker to array marker. You can add any data that you want. and simply call it, set it or get it.

    the sample like this one:

    markers[0].metadata.id  
    

提交回复
热议问题