Please checkout the apex class below :
Geocoding
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class Vlog_GoogleApiApex { @future(callout=true) public static void parseJSONResponse() { String address='Ajmer+Rajasthan'; 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()); system.debug('###Finish'); system.debug('###Finish'); system.debug('###Finish'); } } |
Reverse Geocoding
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | public class Vlog_GoogleApiApex { @future(callout=true) public static void parseJSONResponse() { String address='26.452304+74.610305'; 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()); system.debug('###Finish'); system.debug('###Finish'); system.debug('###Finish'); } } |
For complete tutorial and output checkout below video :
0 Comments