---
schema_version: "1"
id: 7061a2f19219e0dd426acd4ea6a10ce5c95dbc57df34bf0ba88f5fa5d03113d0
title: Geolocation Custom Field
collection: admin
version: current
locale: en-us
portal_url: https://docs.salesforce.com/admin/current/en-us/platform/264-0-0/custom_field_geolocate_overview.md
canonical_url: https://help.salesforce.com/s/articleView?id=platform.custom_field_geolocate_overview.htm&release=264.0.0&type=5
source_site: help.salesforce.com
content_type: documentation
content_hash: a2f0bde590816790dd9a8cc59225ca1fec64ef0945857751ba9393f356667cd9
description: The geolocation custom field allows you to identify locations by their latitude and longitude and to calculate distances between locations.
products:
  - Salesforce Platform
  - Security
release: "264"
---
# Geolocation Custom Field

The geolocation custom field allows you to identify locations by their latitude and longitude and to calculate distances between locations.

### Required Editions

<table class="slds-table slds-table_bordered slds-max-medium-table_stacked slds-m-bottom_small edition"><colgroup><col></colgroup><tbody><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: both Salesforce Classic and Lightning Experience</td></tr><tr class=""><td class="slds-cell-wrap" style="vertical-align:top;">Available in: <strong>All</strong> Editions</td></tr></tbody></table>

You can calculate the distance between two geolocation fields, such as between a warehouse and a store. Or you can calculate the distance between a geolocation field and a pair of latitude and longitude coordinates, such as between a warehouse and 37.794016°, -122.395016°—the location also known as San Francisco. Latitude values must be within `-90` and `90`. Longitude values must be within `-180` and `180`.

Geolocation is a compound field that counts toward your org’s limits as three custom fields: one for latitude, one for longitude, and one for internal use. Support for the compound field (geolocation) versus the field’s components (latitude and longitude) varies depending on the functionality you’re using in Salesforce. For example, you can create list views that show the field and its components, but you can’t select the compound geolocation field in Apex. You can run SOQL queries only on a geolocation field’s components.

## Considerations for Compound and Geolocation Fields

Compound fields, including geolocation fields, have these limitations.

- Compound fields are read-only. To update field values, modify the individual field components.
- Compound fields are accessible only through the SOAP API, REST API, and Apex. The compound versions of fields aren’t accessible anywhere in the Salesforce user interface.
- Although compound fields can be queried with the `Location` and `Address` Apex classes, they’re editable only as components of the actual field. Read and set geolocation field components by appending “\_\_latitude\_\_s” or “\_\_longitude\_\_s” to the field name, instead of the usual “\_\_c.” For example:
    
    ```java
    Double theLatitude = myObject__c.aLocation__latitude__s;
    myObject__c.aLocation__longitude__s = theLongitude;
    ```
    
    You can’t access or set the compound value.
- You can’t use compound fields in Visualforce—for example, in an `<apex:outputField>`. To access or update field values, use the individual field components.
- If you select compound fields for export in the Data Loader, they cause error messages. To export values, use individual field components.
- Custom geolocation and location fields on standard addresses aren’t supported with email templates.
- You can’t use compound fields in lookup filters, except to filter distances that are within or not within given ranges. You can use distance lookup filters only in the Metadata API.
- The only formula functions that you can use with compound fields are `ISBLANK`, `ISCHANGED`, and `ISNULL`. You can’t use `BLANKVALUE`, `CASE`, `NULLVALUE`, `PRIORVALUE`, or the equality and comparison operators with compound fields. The equality and comparison operators include `=` and `==` (equal), `<>` and `!=` (not equal), `<` (less than), `>` (greater than), `<=` (less than or equal), `>=` (greater than or equal), `&&` (AND), and `||` (OR).

## Considerations for Geolocation Fields

This list contains limitations for geolocation fields.

- Geolocation fields aren’t supported in custom settings.
- Geolocation fields aren’t available in dashboards or Schema Builder.
- Geolocation fields are available in Visual Workflow and in formula-based workflow and approvals, but they can’t be used in filter-based workflow updates and approvals.
- `DISTANCE` formulas are supported in:
    - Entry criteria for workflow rules and approval processes
    - Field update actions in workflow rules and approval processes
    - Custom validation rules
    - Lookup filters (in the Metadata API only)
- Geolocation fields and latitude and longitude on standard addresses aren’t supported in Salesforce to Salesforce.
- In Developer, Professional, Enterprise, Unlimited, and Performance editions, Salesforce can automatically add or update geolocation fields for Account, Contact, Lead, and WorkOrder records. To use this feature, your administrator must enable the geo data integration rule for each object. For all other objects and editions, set values for latitude and longitude by using SOQL, SOAP or REST API, or a geocoding service. You can then use address fields as locatable values. To find geocoding services, search AppExchange.
- Geolocation fields are supported in SOQL with these limitations.
    
    - `DISTANCE` and `GEOLOCATION` are supported in `WHERE` and `ORDER BY` clauses in SOQL, but not in `GROUP BY`. `DISTANCE` is supported in `SELECT` clauses.
    - `DISTANCE` supports only the logical operators > and <, returning values within (<) or beyond (>) a specified radius.
    - When using the `GEOLOCATION` function in SOQL queries, the geolocation field must precede the latitude and longitude coordinates. For example, `DISTANCE(warehouse_location__c, GEOLOCATION(37.775,-122.418), 'km')` works but `DISTANCE(GEOLOCATION(37.775,-122.418), warehouse_location__c, 'km')` doesn’t work.
    - Apex bind variables aren’t supported for the units parameter in the `DISTANCE` function. This query doesn’t work.
        
        ```java
        String units = 'mi';
        List<Account> accountList = 
            [SELECT ID, Name, BillingLatitude, BillingLongitude 
             FROM Account 
             WHERE DISTANCE(My_Location_Field__c, GEOLOCATION(10,10), :units) < 10]; 
        ```
    
    For more information and examples, see the [SOQL and SOSL Reference](https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/).

#### See Also

- [Custom Field Types](https://help.salesforce.com/s/articleView?id=platform.custom_field_types.htm&release=264.0.0&type=5 "Salesforce supports various field types, allowing you to select the right one for your data. You can also convert an existing field to a different data type if needed.. When you have data that doesn’t match any of the standard fields, your admin can create a custom field for that data. For example, create a Middle Name field for contacts to capture additional information.")
- [Custom Field Attributes](https://help.salesforce.com/s/articleView?id=platform.custom_field_attributes.htm&release=264.0.0&type=5 "A custom field has different attributes depending on its field type.")