Input Location

lightning:inputLocation

Represents a geolocation compound field that accepts a latitude and longitude value. This component requires API version 41.0 and later.

For Aura components only. For LWC development, use lightning-input-location.

For Use In

Lightning Experience, Experience Builder Sites, Salesforce Mobile App, Lightning Out (Beta), Standalone Lightning App, Mobile Offline

A lightning:inputLocation component represents a geolocation compound field that accepts user input for a latitude and longitude value. Latitude and longitude are geographic coordinates specified in decimal degrees. The geolocation compound field allows you to identify locations by their latitude and longitude. The latitude field accepts values within -90 and 90, and the longitude field accepts values within -180 and 180. An error message is displayed when you enter a value outside of the accepted range.

Here are a few examples of latitudes: -30, 45, 37.12345678, -10.0. Values such as 90.5 or -90.5 are not valid latitudes. Here are a few examples of longitudes: -100, -120.9762, 115.84. Values such as 180.5 or -180.5 are not valid longitudes.

This example displays a geolocation compound field with a latitude of 37.7938460 and a longitude of -122.3948370.

1<aura:component>
2  <lightning:inputLocation
3    label="My Coordinates"
4    latitude="37.7938460"
5    longitude="-122.3948370"
6  />
7</aura:component>

You can use custom labels that display translated values. For more information, see the Lightning Aura Components Developer Guide.

Input Validation 

Client-side input validation is available for this component. You can require the user to make a selection by setting required="true". An error message is automatically displayed when an item is not selected and required="true".

To check the validity states of an input, use the validity attribute, which is based on the ValidityState object. You can access the validity states in your client-side controller. This validity attribute returns an object with boolean properties.

You can override the default message by providing your own value for messageWhenValueMissing.

To programmatically display error messages on invalid fields, use the reportValidity() method. For custom validity error messages, display the message using setCustomValidityForField() and reportValidity(). For more information, see the lightning:input documentation.

Attributes 

NameDescriptionTypeDefaultRequired
bodyThe body of the component. In markup, this is everything in the body of the tag.Aura.Component[]
classA CSS class for the outer element, in addition to the component's base classes.String
disabledSpecifies whether the compound field should be disabled. Disabled fields are grayed out and not clickable. This value defaults to false.Boolean
fieldLevelHelpHelp text detailing the purpose and function of geolocation compound field.String
labelText label for the geolocation compound field.String
latitudeThe latitude value. Latitude values must be within -90 and 90.String
longitudeThe longitude value. Longitude values must be within -180 and 180.String
onblurThe action triggered when the input releases focus.Aura.Action
onchangeThe action triggered when the value changes.Aura.Action
onfocusThe action triggered when the input receives focus.Aura.Action
readonlySpecifies whether the compound field is read-only. This value defaults to false.Boolean
requiredSpecifies whether the compound field must be filled out. An error message is displayed if a user interacts with the field and does not provide a value. This value defaults to false.Boolean
titleDisplays tooltip text when the mouse moves over the element.String
variantThe variant changes the appearance of the geolocation compound field. Accepted variants include standard, label-hidden, label-inline, and label-stacked. This value defaults to standard. This value defaults to standard. Use label-hidden to hide the label but make it available to assistive technology. Use label-inline to horizontally align the label and geolocation fields. Use label-stacked to place the label above the geolocation fields.String

Methods 

NameDescriptionArgument NameArgument TypeArgument Description
checkValidityReturns the valid property value (Boolean) on the ValidityState object to indicate whether the latitude and longitude fields have validity errors.
reportValidityDisplay error messages if the latitude or longitude field is invalid.
setCustomValidityForFieldSets a custom error message to be displayed for the latitude or longitude field when the value is submitted.messageStringThe string that describes the error. If message is an empty string, the error message is reset.
fieldNameStringThe name of the geolocation field, either longitude or latitude.
showHelpMessageIfInvalidShows the help message if the latitude or longitude fields are in an invalid state.