function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AbAb 

Trigger to calculate time and distance using Google Maps API in Salesforce.com

Hello,

I am integrating Google maps with Salesforce using below link
http://www.bulkified.com/How+to+use+the+Google+Maps+API+in+Salesforce.com

This above example gives a VF page to calculate.

I have below Objects:
ObjectA__C
CustomField__1
CustomField__2
CustomField__3

When Address is entered in CustomField__1 and CustomField__2, I want to calcuate the distance and time and fill it automatically in CustomField__3.

thanks for suggestion !
 
Best Answer chosen by Ab
SRKSRK
the link you have posted they have givien an exmaple as mentioned below to get the distance between two address
, once you have the JSON you can write JSON parser 

OR you can try JSON serialize to convert JSON into Object and thenyou can easy move the data into your custom object


public String getJsonResults( String address1, String address2)
{
HttpRequest req = new HttpRequest();
Http http = new Http();
req.setMethod('GET');
String url = 'https://maps.googleapis.com/maps/api/distancematrix/json' + '?origins=' + address1 + '&destinations=' + address2 + '&mode=driving' + '&sensor=false' + '&language=en' + '&units=imperial';
req.setEndPoint(url);
HTTPResponse resp = http.send(req); return jsonResults;
}