0

Is there a method to obtain the latitude and longitude from a zip code input without requiring a Google API key? I tried to use this MapAnything enpoint method but it didn't work: https://help.salesforce.com/articleView?id=000353820&type=1&mode=1

My ultimate goal is to be able to create search functionality in which a user inputs a zip code and a list of accounts that are within a specified range (5 mi, 10 mi, etc) returns as a result. I know about the method Location.getDistance(loc1, loc2, 'mi') but it only works with lat/lon. https://developer.salesforce.com/docs/atlas.en-us.apexref.meta/apexref/apex_class_system_Location.htm

0

For standard address fields, if you turn on

Maps and Location Services

https://help.salesforce.com/articleView?id=sf.customize_maps.htm&type=5%C2%A0%C2%A0

you should get new geolocation fields as part of the address compound fields:

For Accounts it is:

MailingLatitude, MailingLongitude, BillingLatitude and BillingLongitude

You can then use these fields to reconstruct the Location.distance methods.

If you need to use custom addresses, then you need to save the geolocation data yourself.

3
  • I know how to obtain the lat/lon from the Account records. The issue is getting the lat/lon from a zip code input field. I'm looking for an option that doesn't require creating a new object to store the zip code and lat/lon information, as there are 41,692 zip codes in the US and it would require maintenance (district lines redrawn, census changes, etc..)
    – Jay
    Jul 14 at 12:16
  • If it is a custom field, you will need some service to reverse geocode that for you. How many do you need to do per day? Google has a free tier and there are other services that have free tiers: geoapify.com/reverse-geocoding-api
    – CyberJus
    Jul 14 at 14:36
  • I see that I need a service in order to do what I need. I’ll present these options to the client. Thanks!
    – Jay
    Jul 14 at 17:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.