function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ankita VashisthAnkita Vashisth 

How to calculate distance between two contact using vf page.

Dushyant SonwarDushyant Sonwar
Hi Ankita , 

You can do this using geocodes.

once you get contact mailing address (latitude , longitude) geocodes

you can calculate distance using distance method.

Hope this helps.
Deepali KulshresthaDeepali Kulshrestha
Hi Ankita,

As per your requirement you can calculate the geolocation between salesforce contact  , see the links below:

Salesforce has launched a while ago, a new field: Geolocation Custom Field. Which has
the possibility to calculate distances? But it's still in a beta phase (Winter 13): (

I believe you can contact Salesforce to request access to this beta release.

There are as well a couple of API's out there which you can use to calculate the distance. But you
will need to use coding in Apex/Javascript/... A couple of examples:


I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.

Thanks and Regards,
Deepali Kulshrestha