I have a Google script which takes address in the url parameters and returns the latitude and longitude. It is deployed as a web app. Link :
I have a trigger on Listings__c which takes the address of the listing (when inserted/updated), passes it to a future method in an apex class. The class then calls the Google Web App and passes it the address in the url parameters doing http request and suppose to get back the latitude and longitude in the response.
My problem is the http request does not return anything back. I am not sure if I am doing the call to the web app correctly.
This is a sample method to show the way I am calling the web app:
public class LocationClass() {
@future (callout=true)
public static void getLocation() {
String address = 'Times Square, New York, NY';
//CONNSTRUCT AN HTTP REQUEST
Http http = new Http();
HttpRequest req = new HttpRequest();
req.setEndpoint('https://script.google.com/macros/s/AKfycbxV70DhVKCPppaGC6AKN8yarNUCN54VVBY7yLyCE5lxeICfB77y/exec?'+EncodingUtil.urlEncode(address, 'UTF-8'));
req.setMethod('GET');
req.setTimeout(6000);
try {
HttpResponse res = http.send(req);
System.debug('OOOOOOOOO response : ' + res.getBody());
} catch(Exception e) {}
}
}
This is a sample method, you can remove the annotation and try to run it by doing LocationClass.getLocation();
Thanks.