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.
https://help.salesforce.com/articleView?id=data_dot_com_clean_admin_automatically_get_geocodes_for_addresses.htm&type=0

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

you can calculate distance using distance method.
https://salesforce.stackexchange.com/questions/196705/how-to-calculate-distance-between-two-records

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):

 https://help.salesforce.com/HTViewHelpDoc?id=custom_field_geolocate_overview.htm&language=en_US (https://help.salesforce.com/HTViewHelpDoc?id=custom_field_geolocate_overview.htm&language=en_US)

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:

1.http://salesforce.stackexchange.com/questions/557/calculate-distance-between-two-places-on-accounts-from-a-vf-page
2.http://www.bulkified.com/How+to+use+the+Google+Maps+API+in+Salesforce.com



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
www.kdeepali.com