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.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *