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

To download a PDF copy of the presentation above

check to receive weekly updates on more of such awesome guides

(You'll never be spammed on my watch. And that's a promise)