As of API 32.0, it's easy to create a map in Visualforce with <apex:map>
and <apex:mapMarker>
even takes string addresses as a position and will geocode the address automatically. You can see an example in the dev guide.
I'm using the map to show several addresses on a custom object:
<apex:map width="600px" height="400px" mapType="roadmap"
center="{!Account.BillingStreet},{!Account.BillingCity},{!Account.BillingState}">
<apex:repeat value="{! MyObj__c.Addresses }" var="addr">
<apex:mapMarker title="{! addr.Name }"
position="{!addr.MailingStreet},{!addr.MailingCity},{!addr.MailingState}"
/>
</apex:repeat>
</apex:map>
This works all well and good, as the page geocodes the address and plops a marker on the map. However, we want to do some DISTANCE based SOQL queries with those locations. There are third-party APIs and plugins to geocode arbitrary addresses in Salesforce, but we'd rather stick with platform features. And indeed, the platform is capable of geocoding up to 10 arbitrary locations in a page request.
Is there ANY WAY to get the lat/long that resulted in this mapping that can be sent back to the server for storage? How can we cache this very useful data?