---
schema_version: "1"
id: 4267ca9f2339dfcc1dab2a28d199ed23ab16d553e85f4e643bf5a21430b96943
title: Geolocation Compound Field
collection: legacydeveloper
version: current
locale: en-us
portal_url: https://docs.salesforce.com/legacydeveloper/current/en-us/object_reference/compound_fields_geolocation.md
canonical_url: https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields_geolocation.htm
source_site: developer.salesforce.com
content_type: documentation
content_hash: 92ec6196f5f1a04ea51ed2996ba36fd9c5e16ec41754c933c7094300db34b809
description: Geolocation fields are accessible in the SOAP and REST APIs as a Location—a structured compound data type—or as individual latitude and longitude elements.
---
# Geolocation Compound Field

Geolocation fields are accessible in the SOAP and REST APIs as a Location—a structured compound data type—or as individual latitude and longitude elements.

In API versions 26.0 and later, geolocation fields are available in the SOAP and REST APIs as a compound field of type Location. This structured data type contains the following fields.

- latitude
- longitude

![Note](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/images/icon_note.png)

#### Note

SOAP calls that use API versions earlier than 30.0 return geolocation compound values as strings. See “Returned Geolocation Data Types” later in this topic.

Geolocation fields are provided on many standard objects, such as Account, Contact, Quote, and User, as part of their address field or fields. Geolocation fields can also be added as custom fields to standard or custom objects.

![Note](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/images/icon_note.png)

#### Note

- A geolocation compound field is read-only, although its latitude and longitude subfields are editable. You can only access compound fields using the SOAP or REST API. For more information about working with compound fields and their subfields, see [Compound Field Considerations and Limitations](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields_limitations.htm "Address and geolocation compound fields are convenient and result in more concise, clear code. Here are some things to consider when using them in your apps.").
- Although geolocation fields appear as a single field in the user interface, custom geolocation fields count as _three_ custom fields towards your organization’s limits: one for latitude, one for longitude, and one for internal use.

## Retrieving Compound Geolocation Fields

Using compound fields can simplify code that works with geolocations, especially for SOQL queries. SOQL SELECT clauses can reference geolocations directly, instead of the individual component fields.

SELECT location\_\_c 
FROM Warehouse\_\_c

To write code that’s compatible with API versions earlier than 26.0 and with API versions 26.0 and later, use the individual latitude and longitude fields.

SELECT location\_\_latitude\_\_s, location\_\_longitude\_\_s 
FROM Warehouse\_\_c

## Returned Geolocation Data Types

A compound geolocation field value is returned as the structured data type Location. Code that works with compound geolocation fields must reference the individual components of the returned value. See the sample code in [Address Compound Fields](https://developer.salesforce.com/docs/atlas.en-us.object_reference.meta/object_reference/compound_fields_address.htm#compound_fields_example_soap_retrieve_address).

In API versions earlier than 30.0, SOAP calls return compound geolocation field values as strings, instead of as a structured data type, for backward compatibility. If you plan to display your latitude and longitude values or pass them to a service that expects strings, use the values that are returned. If you plan to use the values in mathematical calculations or pass them to a map service that expects numbers, cast the results to numbers.

The string value format is:

API location: \[latitudeValue longitudeValue\]

An example of a regular expression to parse out the latitude and longitude values is:

API location: \\\[(\[-+\]?\\d{1,2}(\[.\]\\d+)?) (\[-+\]?\\d{1,3}(\[.\]\\d+)?)\]

The first capture is the latitude, and the third is the longitude.