How to Enable Map & Calculate Distance Between Two Locations
You can enable Map & Location services in Salesforce to make it convenient for users when adding an address to 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 field name 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 calculating directions between those points on 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
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