Formatted Address
lightning-formatted-address
Displays a formatted address with a link to the given location on Google Maps. The link is opened in a new tab. A static map can be displayed with the address for better context.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App
A lightning-formatted-address component shows addresses in a format and field order
that’s determined by the user’s Salesforce locale.
Specify a valid address using attributes for street, city, country, province, and
postal-code.
This example specifies an address.
1<template>
2 <lightning-formatted-address
3 street="1 Market St."
4 city="San Francisco"
5 country="US"
6 province="CA"
7 postal-code="94105"
8 >
9 </lightning-formatted-address>
10</template>The output looks like this in the en-US locale.
1 Market St.
San Francisco, CA 94105
US
By default, the address renders as a link that
opens the given location in Google Maps in a new tab. The link
follows the format https://www.google.com/maps/?q=your+address.
In the example, the link corresponds to
https://www.google.com/maps/?q=121%20Spear%20St.%0ASan%20Francisco,%20CA%2094105%0AUS.
Specify the disabled attribute to show the address in plain text
without a link.
Specify Coordinates for Mapping
You can provide the latitude and longitude attributes in addition to
the address fields. This configuration enables faster map rendering by avoiding the
geocode processing that’s required for street addresses on Google Maps.
The formatted address shows the street address fields,
but the link URL uses the latitude and longitude for Google Maps.
This example specifies an address and uses latitude and longitude for mapping.
1<template>
2 <lightning-formatted-address
3 street="1 Market St."
4 city="San Francisco"
5 country="US"
6 province="CA"
7 postal-code="94105"
8 latitude="37.792179"
9 longitude="-122.392735"
10 >
11 </lightning-formatted-address>
12</template>The link URL with latitude and longitude follows the format
https://www.google.com/maps/?q=37.792179,-122.392735.
Show a Static Map
Use the show-static-map attribute to show a map with your address.
The address and the static map are both linked to Google Maps.
1<template>
2 <lightning-formatted-address
3 street="1 Market St."
4 city="San Francisco"
5 country="US"
6 province="CA"
7 postal-code="94105"
8 show-static-map
9 >
10 </lightning-formatted-address>
11</template>Address Line Truncation
By default, each line of address uses the slds-truncate class.
To remove address line truncation, set variant="plain". This configuration renders each address line without truncating it.
1<template>
2 <lightning-formatted-address
3 street="45 Ffordd Penmynydd"
4 city="St Mary's Church in the Hollow of the White Hazel near a Rapid Whirlpool and the Church of St. Tysilio near the Red Cave"
5 country="United Kingdom"
6 province="Wales"
7 postal-code="LL61 5UJ"
8 variant="plain"
9 disabled
10 ></lightning-formatted-address>
11</template>Accessibility
lightning-formatted-address specifies the aria-label description on the link so screen readers can announce the destination address. The aria-label description dynamically combines the action and the address using the format:
1Show in Google Maps, {your_formatted_address}The description provides clear intent to assistive technologies, making it obvious that interacting with the link opens the location externally.
If you specify the disabled attribute on the component, the address is shown in plain text instead of a link.
See Also
Object Reference for the Salesforce Platform: Field Types
Attributes
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| city | The city detail for the address. | string | ||
| country | The country detail for the address. | string | ||
| disabled | If present, the address is displayed as plain text and cannot be clicked or focused on. | boolean | false | |
| latitude | The latitude of the location if known. Latitude values must be within -90 and 90. | string | ||
| locale | The locale of the address. The default value is 'en-US'. | string | ||
| longitude | The longitude of the location if known. Longitude values must be within -180 and 180. | string | ||
| postal-code | The postal code detail for the address. | string | ||
| province | The province detail for the address. | string | ||
| show-static-map | Displays a static map of the location using Google Maps. This value defaults to false. | false | ||
| street | The street detail for the address. | string | ||
| variant | Whether the slds-truncate class is assigned to each address line. Accepted variants are truncate and plain. The default variant is truncate. | string | truncate |
Methods
| Name | Description | Argument Name | Argument Type | Argument Description |
|---|---|---|---|---|
| click | Simulates a mouse click on the address and navigates to Google Maps on a new tab. | |||