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
JPKatoJPKato 

Find the closest campus using Geolocation, Google Maps, and Address...

I would like to create a visualforce page that will use the address of a Contact in Salesforce, and determine which one of our ground campus locations is the closest, and display the campus name and distance. I assume that I would need the Latitude, Longitude coordinates for each campus, then somehow tie that into the directions portion of Google Maps... But I'm honestly not sure where to begin with this.
I have found this page: 

http://help.salesforce.com/apex/HTViewHelpDoc?id=custom_field_geolocate_overview.htm#custom_field_geolocate_overview&language=en

which goes into some detail about using the "distance formula" but I am new to Apex coding and using geolocation information, and I don't know how I would access the directions function of Google Maps to utilize and compare the distances to each campus, then display the smallest value/distance.

Any input would be greatly apreciated!
Andy BoettcherAndy Boettcher
Google Maps itself isn't going to give you back any of the comparison information I think you're looking for.  There are many AppExchange packages out there that do this for you if you want to start there.

Outside of that - if you're looking to hack through this as your "baptism of fire" to Apex (*smile*) then you need to partner up with the Google Geocoding API (paid) or the Mapquest Public Api (free to a point) to get this information, then you can do some SOQL calculation magic (http://salesforce.stackexchange.com/questions/32585/what-formulae-does-the-geolocation-distance-use) to help you out.

Does that help give you a start?
Gatorrr7Gatorrr7