Lightning Web Component Google Maps

Let us discuss here how to use the Google maps with Lightning Web Component Map. A lightning-map component displays a map of one or more locations. To display maps Pass the location to be displayed via the component’s map-markers property. map-markers is an array of markers that indicate location. A marker contains

  • Location Information: This can be a coordinate pair of latitude and longitude or an address composed of address elements.
  • Descriptive Information: This is information like title, description and an icon which is information relevant to the marker but not specifically related to location.

The location information supports the following address elements: City, Country, PostalCode, State, and Street. Note that to support reliable geocoding of addresses, if Street is specified then at least one of City, Country, PostalCode or State must be specified. Here’s an example of a marker that uses address elements.


Here’s an example of a marker that uses coordinates for latitude and longitude.


For each map marker in the array of map markers, provide either latitude and longitude coordinates or address elements. If you specify both in a single marker, latitude and longitude get precedence.

When displaying a list of addresses, you must also pass the markers-title property, which displays a heading for your locations.

1.Create an Apex Class

The following apex class will get the account location information and pass it to the web components. Use the following SFDX command.

Here is the code

2. Create a Lightning Web component 

Create a lightning web component to display the map. use this SFDX command to create a web component.

Here is the MapEx.html code

Here is the MapEx.js JavaScript controller code

Here is the MapEx.js-meta.xml configuration file

3.Push Changes to scratch org 

Now push the changes to scratch org using this below command.

Add this web component to the record page and you can able to see the map as shown below.