How to Enable Map & Calculate Distance Between Two Locations

Salesforce Map Geolocation

You can enable Map & Location services in Salesforce to make it convenient for users when adding address on an Account, Contact, or Lead. It uses Google Maps to display maps on standard address fields and helps users enter new addresses with autocomplete. 

Having said that, this feature is only available in Professional, Enterprise, Performance, and Unlimited editions. As it is not available in Developer edition, you need to test it out in a Sandbox first before enabling in production.

Calculate Distance Between Two Locations

Also, if you wish to calculate the distance between two locations in Salesforce then you can do that declaratively using the DISTANCE() function. Distance is calculated and displayed as a number.

You can calculate the distance between:

  • two standard address fields
  • standard address field and a custom geolocation field
  • two custom geolocation fields
  • a custom geolocation field and fixed coordinates

You can specify the unit, miles or kilometers, in the function when creating the formula field. However, the unit is not returned with the value. Hence, it is recommended to specify it in your formula name field explicitly for your users to know.

Although this is a great feature, there is a caveat to it. The distance is calculated as a straight line, regardless of geography and topography between the two points. So, you might see some difference in the value that is returned and the actual distance can vary when calculated directions between those points on the Google maps.

Here is a short guide on how to enable map & location services and calculate the distance between two locations in Salesforce. The guide covers:

  • Enable Data Integration Rules
  • Enable Maps and Location Settings
  • Create a Formula Field with DISTANCE() Formula
  • Create a Record & Verify Formula Field

NOTE: Certain sections of the guide will appear as locked in the free preview. You can download the unlocked version of the guide in PDF format by subscribing to our “All Access” Pass through the link below.

Not an “All Access” Pass Member Yet?

Get Download Access to this & 150+ More Step-by-Step Guides with “All Access” Pass. A simple and single plan to access our entire library of courses, guides, workshops & masterclasses on Salesforce.

References & Useful URLs

3 thoughts on “How to Enable Map & Calculate Distance Between Two Locations”

  1. This would be great to determine the distance between a client address and our company address… I tried following your instructions but could not insert the address for our company (it is not a field on the Lead object)

    I tried using the Organization Address ($Organization.Address) but it came up with an error:
    Error: Incorrect number of columns as arguments to distance function. Got: _Organization.Street_, _Organization.City_, _Organization.State_, _Organization.PostalCode_, _Organization.Country_, _Organization.Latitude_, _Organization.Longitude_, _Organization.GeocodeAccuracy_

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top
Introducing All Access Pass