Categories
JavaScript Answers

How to add ID’s to Google map markers with JavaScript?

Spread the love

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.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.