Geocoding is the computational process by which a physical address is converted into geographic coordinates, which can be used for a variety of mapping applications.
Sales and marketing professionals had challenges assigning territories and find their nearby prospects about a location. To get some useful data into the system, Salesforce partners and customers had to use number fields to store latitude and longitude pairs by having to manually type.
Salesforce unlocked a whole new way to understand their customers and run a business. Hence, they introduced the Geolocation feature in Winter 2013, which enabled their customers to identify locations by their latitude and longitude. Subsequently, this feature was further enhanced to Geocode, which converts addresses into geographic coordinates like latitude and longitude and position the map.
In summer’16, salesforce released this feature.
https://releasenotes.docs.salesforce.com/en-us/summer16/release-notes/rn_general_geocodes_aloha.htm
Geocoding software is implemented in a variety of industries, including but not limited to:
However, you can also get Geolocations for addresses in the records, such as Accounts, Leads and Contracts in Salesforce by making callouts to Google API.
Geocoding is the conversion of physical human-readable addresses of places into latitude and longitude geographical coordinates. This process is known as “Geocoding,” while the reverse case (that is, converting latitude and longitude coordinates into physical addresses) is known as “Reverse Geocoding.” To clarify this explanation here is an example using the datacamp USA office address
public class Geo_apicall { @future(callout=true) public static void parseJSONResponse() { String address='Kharadi+Pune+Maharastra'; String key='AIzaSyC5Z3twwN_hX_uP1JrDnY_726nH26Zb058'; Http httpProtocol = new Http(); // Create HTTP request to send. HttpRequest request = new HttpRequest(); // Set the endpoint URL. String endpoint = 'https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+key; request.setEndPoint(endpoint); // Set the HTTP verb to GET. request.setMethod('GET'); // Send the HTTP request and get the response. // The response is in JSON format. HttpResponse response = httpProtocol.send(request); System.debug('####Body : '+response.getBody()); } }
If we are using the standard edition for API Callouts to Google, then we need to use the API KEY in the End Point URL. And then it will be like:
https://maps.googleapis.com/maps/api/geocode/json?address=Street+City+State&key=YOUR_API_KEY
However, if we are using the premium version for API Callouts to Google, then we need to use Client Id as a parameter in the End Point URL. Something like:
https://maps.googleapis.com/maps/api/geocode/json?address=Street+City+State&client=YOUR_CLIENT_ID&signature=SIGNATURE
This will get the Geolocation as a response from Google API. We can then use JSON to fetch the Geolocation with two parameters: Latitude and Longitude.
public class ReverseGeo_apicall { @future(callout=true) public static void parseJSONResponse() { String address='18.5538+73.9477'; String key='AIzaSyC5Z3twwN_hX_uP1JrDnY_726nH26Zb058'; Http httpProtocol = new Http(); // Create HTTP request to send. HttpRequest request = new HttpRequest(); // Set the endpoint URL. String endpoint = 'https://maps.googleapis.com/maps/api/geocode/json?address='+address+'&key='+key; request.setEndPoint(endpoint); // Set the HTTP verb to GET. request.setMethod('GET'); // Send the HTTP request and get the response. // The response is in JSON format. HttpResponse response = httpProtocol.send(request); System.debug('####Body : '+response.getBody()); } }
To understand more about google maps API.
https://developers.google.com/maps/gmp-get-started
Thanks for Reading…