You need to sign in to do that
Don't have an account?
Any known issues w/ Google Maps Distance Matrix post Winter 16 Release?
Hello, We have had random disruptions and issues with our Google Maps API call this week. Does anyone know of issues with this call and wether or not this could be a Winter 16 release issue. Our org was updated over the weekend and the issues began on Monday. What we have is an object in SFDC built to collect Origin Zip Code and Destination Zip Code and the call goes to GMDM and returns the distance in meters. It has returned too many zeros this week ocasionally returning results with a refresh or clone and working some hours of the day, some hours not.... Help please!
public class ZipGeoCode{
@future (callout=true) // future method needed to run callouts from Triggers
static public void getDistance(id carquoteId){
// gather account info
CarQuotes__c a = [SELECT Open_Carrier__c, Origin_Zip__c, Origin_Street__c, Origin_City__c, Origin_State__c, Origin_Country__c, Destination_Zip__c, Destination_Street__c, Destination_City__c, Destination_State__c, Destination_Country__c, NeedDistance__c FROM CarQuotes__c WHERE id =: carquoteId];
if(a.NeedDistance__c == True){
// build callout
String ostreet = ' ';
String ocity = ' ';
String ostate = ' ';
String ozip = ' ';
String ocountry = ' ';
String dstreet = ' ';
String dcity = ' ';
String dstate = ' ';
String dzip = ' ';
String dcountry = ' ';
if(a.Origin_Street__c != null){ostreet = a.Origin_Street__c;}
if(a.Origin_City__c != null){ocity = a.Origin_City__c;}
if(a.Origin_State__c != null){ostate = a.Origin_State__c;}
if(a.Origin_Country__c != null){ocountry = a.Origin_Country__c;}
if(a.Origin_Zip__c != null){ozip = a.Origin_Zip__c;}
if(a.Destination_Street__c != null){dstreet = a.Destination_Street__c;}
if(a.Destination_City__c != null){dcity = a.Destination_City__c;}
if(a.Destination_State__c != null){dstate = a.Destination_State__c;}
if(a.Destination_Country__c != null){dcountry = a.Destination_Country__c;}
if(a.Destination_Zip__c != null){dzip = a.Destination_Zip__c;}
String originaddress = EncodingUtil.urlEncode(ostreet + ' ' + ocity + ' ' + ostate + ' ' + ocountry + ' ' + ozip, 'UTF-8');
String destaddress = EncodingUtil.urlEncode(dstreet + ' ' + dcity + ' ' + dstate + ' ' + dcountry + ' ' + dzip, 'UTF-8');
Http h = new Http();
HttpRequest req = new HttpRequest();
//req.setEndpoint('http://maps.googleapis.com/maps/api/distancematrix/json?origins=' + a.Origin_Zip__c + '&destinations=' + a.Destination_Zip__c + '&mode=driving&units=imperial&sensor=false');
req.setEndpoint('http://maps.googleapis.com/maps/api/distancematrix/json?origins='+ originaddress +'&destinations=' + destaddress +'&mode=driving&units=imperial&sensor=false');
//req.setEndpoint(EncodingUtil.urlEncode('http://maps.googleapis.com/maps/api/distancematrix/json?origins=' + a.Origin_Street__c + '+' + a.Origin_City__c + '+' + a.Origin_State__c + '+' + a.Origin_Zip__c + '&destinations=' + a.Destination_Street__c + '+' + a.Destination_City__c + '+' + a.Destination_State__c + '+' + a.Destination_Zip__c + '&mode=driving&units=imperial&sensor=false', 'UTF-8'));
//req.setEndpoint(GEOCODING_URI_BASE + EncodingUtil.urlEncode(address, 'UTF-8'));
req.setMethod('GET');
req.setTimeout(60000);
integer distance = null;
string tdistance = null;
//HttpResponse res = h.send(req);
// callout
HttpResponse res = h.send(req);
System.debug(res.getBody());
// parse coordinates from response
JSONParser parser = JSON.createParser(res.getBody());
while (parser.nextToken() != null) {
if ((parser.getCurrentToken() == JSONToken.FIELD_NAME) &&
(parser.getText() == 'distance')){
parser.nextToken(); // object start
while (parser.nextToken() != JSONToken.END_OBJECT){
String txt = parser.getText();
parser.nextToken();
if (txt == 'text')
tdistance = parser.getText();
else if (txt == 'value')
distance = parser.getIntegerValue();
}
}
}
// update coordinates if we get back
if (distance != null){
a.Distance_Meters__c = distance;
//a.tdistance__c = tdistance;
a.NeedDistance__c = False;
//a.Description1__c = req.getEndpoint();
//a.Description2__c = res.getBody();
//String originaddress = a.Origin_Street__c != null ? a.Origin_Street__c + ' ' : '' +
//a.Origin_City__c != null ? a.Origin_City__c + ' ' : '' +
//a.Origin_State__c != null ? a.Origin_State__c + ' ' : '' +
//a.Origin_Zip__c != null ? a.Origin_Zip__c : '';
//String originaddress = EncodingUtil.urlEncode(a.Origin_Street__c + ' ' + a.Origin_City__c + ' ' + a.Origin_State__c + ' ' + a.Origin_Zip__c, 'UTF-8');
a.Description1__c = 'http://maps.googleapis.com/maps/api/distancematrix/json?origins=' + originaddress + '&destinations=' + destaddress + '&mode=driving&units=imperial&sensor=false';
//a.Description1__c = EncodingUtil.urlEncode(originaddress, 'UTF-8') + '---' + originaddress;
update a;
}
}
Else {
a.Description1__c = 'test';
a.NeedDistance__c = True;
update a;
}
}
}