You are here:
DISTANCE
Calculates the distance between two locations in miles or kilometers.
Use
DISTANCE(mylocation1,
mylocation2, 'unit') and replace
mylocation1 and mylocation2 with two location
fields, or a location field and a value returned by the GEOLOCATION function. Replace
unit with mi (miles) or km (kilometers).
Tips
- The DISTANCE function returns a number data type. Distance is always calculated in decimals, even if you’re displaying the geolocation notation in degrees, minutes, and seconds in the user interface. Specify the number of decimal places to show when you create a custom field.
- The DISTANCE function isn’t available in reports, but it can be used in list views. To use DISTANCE in your reports, set up a formula field, and then reference the field in your reports.
- DISTANCE is the only formula function that can use GEOLOCATION parameters.
- There are limitations on DISTANCE accuracy and equality calculations.
- DISTANCE supports only the logical operators > and <, returning values within (<) or beyond (>) a specified radius.
- Distance is calculated as a straight line, regardless of geography and topography between the two points.
DISTANCE(warehouse_location__c, store_location__c,
'mi')
This formula returns the distance, in miles, between the warehouse and the store. In this
example, warehouse_location__c and store_location__c are the names of two custom geolocation
fields.
DISTANCE(BillingAddress, store_location__c, 'mi')
This formula returns the distance, in miles, between an account’s billing address and a
store. In this example, BillingAddress is the standard
billing address field on an Account object, and store_location__c is the name of a custom geolocation field.
IF(DISTANCE(warehouse_location__c, ShippingAddress,
'mi')<10, "Near", "Far")
This formula updates a text formula field to Near if the distance between the warehouse and the account shipping address compound field is less than 10 miles. Otherwise, it updates the text field to Far.
