+ Start a Discussion
Vrajesh NayakVrajesh Nayak 

Calculate distance between two place in Salesforce

I have reuirement to calculate distance between Shipping location and Customer.
We maintaned customer address(USA) in Account object with Zip code and Shipping location is customer object with full zip code address(USA).

Is there an app? What do I have to do.

Thanks
Vivek_PatelVivek_Patel
Hi Vrajesh,

You can use google map in your VF and with some javascript code you can get the distance between two places.

Regards,
Vivek Patel.

Please like or mark as best answer if this answers your query to help other find the correct answer and improve the quality of developer forum.
Vivek_PatelVivek_Patel
Hi Vrajesh,

Try DISTANCE function in formula fields. Just provide two Location fields and the function will calculate the distance betweent those to points in miles or kelometers

DISTANCE(mylocation1, mylocation2, 'unit')

For more details - https://help.salesforce.com/htviewhelpdoc?err=1&id=customize_functions_a_h.htm&siteLang=en_US#DAY

Regards,
Vivek Patel.

Please like or mark this as best answer if this answers your question to help others find better answer and improve the quality of developer forum.
Praveen Ettam 9Praveen Ettam 9
If you want to create a calculated field on Account then use the following 
DISTANCE(  GEOLOCATION( BillingLatitude , BillingLongitude ),     GEOLOCATION( Branch_Assigned__r.GeoLocation__Latitude__s , Branch_Assigned__r.GeoLocation__Longitude__s )    , 'mi')

BillingLatittude and BillingLongitude are deafult fields in Account.
Branch_Assigned__r.GeoLocation__Latitude__s and Branch_Assigned__r.GeoLocation__Longitude__s are created automatically in Custom object when you create a GeLocation__C field. 

I am providing the Lat and Log for GeoLocation__C field, these are my Wearhouse.  So now with the above formula I can find the distand between Account BillingAdress and my Wearhouse.