Display Maps in LWC
In this blog, we will look at how to display Google Maps in your Lightning Web Components. Salesforce provides a lightning-map component to display a map of one or more locations, using geocoding data and mapping imagery from Google Maps.
Now, let's look at how to use this component in your Lightning Web component.
HTML:
- Pass the location(s) that you want to display in the map-marker property.
- A marker contains:
- Location Information: A coordinate pair of latitude and longitude, or an address composed of address elements to be geocoded.
- Descriptive Information: Optional title, description, and an icon. These items are relevant to the marker but not specifically related to location.
Display a Single Marker
Let's understand how we can pass single location info in the map-marker and display it on the map.
In this example, we will create a new Lightning Web Component to display the location of the contact on the Contact Page.
Apex Class:
JavaScript:
Output:
In the above example, I have created a lightning web component to display the location of a Contact on the standard contact page.
Now let's look at how we can display multiple addresses.
Display Multiple Addresses
- mapMarkers property will contain a list of multiple addresses.
- markers-title is used to provide a custom heading for the locations.
JavaScript:
Output:
Thank you for reading the blog.
You can share your thoughts with me by dropping a message to me on LinkedIn
You can find my other blogs on my blog page - LWC - Blog
Comments
Post a Comment