Sometimes, we want to add ID’s to Google map markers with JavaScript.
In this article, we’ll look at how to add ID’s to Google map markers with JavaScript.
How to add ID’s to Google map markers with JavaScript?
To add ID’s to Google map markers with JavaScript, we can add custom attributes.
For instance, we write
const marker = new google.maps.Marker({
map,
position,
storeId: id,
});
const storeId = marker.get("storeId");
to create a marker with the Marker constructor.
We add the storeId custom attribute.
Then we call marker.get with the attribute name string to get the attribute value.
Conclusion
To add ID’s to Google map markers with JavaScript, we can add custom attributes.