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
(We have discontinued our premium membership offering. If you are an existing premium member, you can still download the guides by clicking on “DOWNLOAD PDF [PREMIUM MEMBERS]” button. If you are not a premium member and want to download the guides, please sign up for our “All Access” pass. Complete details about this pass is available at this URL.)
References & Useful URLs
- Activate the Data Integration Rule for a Data Service – Help Article (10 mins) – https://help.salesforce.com/articleView?id=ddc_data_integration_rule_activating.htm&type=5
- Provide Maps and Location Services – Help Article (10 mins) – https://help.salesforce.com/articleView?id=customize_maps.htm&type=5
- DISTANCE() Function – Help Article (10 mins) – https://help.salesforce.com/articleView?id=customize_functions_a_h.htm&type=5
- Automatically Get Geocodes for Addresses – Salesforce Summer ’16 Release Notes (10 minutes) – https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_general_geocodes_aloha.htm
3 thoughts on “How to Enable Map & Calculate Distance Between Two Locations”
How to calculate distance between standard address field and a custom geolocation field
Hi Suvarna, you should be able to do this with the “DISTANCE” formula. Please take a look at this help article – https://help.salesforce.com/s/articleView?id=sf.customize_functions_distance.htm&type=5
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_