2

I am trying to get shortest distance between two locations using google Distance Matrix API. To get shortest distance I am passing OPTIMISTIC parameter to trafficModel. To make it work I have to pass client ID or API key. I have both. I don't know how to pass this API key to DistanceMatrixService. Please suggest any ways to achieve this.

js file

var service = new google.maps.DistanceMatrixService();  
service.getDistanceMatrix({
  origins: ["A","B"],
  destinations: ["A","B"],

  travelMode: google.maps.TravelMode.DRIVING,
  drivingOptions: {
     departureTime: new Date(moment().tz(gUserTimeZone).format('MM/DD/YYYY h:mm A')+400), 

     trafficModel :google.maps.TrafficModel.OPTIMISTIC
    },
  unitSystem: google.maps.UnitSystem.IMPERIAL,
  avoidHighways: false,
  avoidTolls: false,
 },function(response){console.log(response);});

1 Answer 1

2

When you use the Google Maps JavaScript API v3 DistanceMatrix, the credentials are included in the API load.

You can use either set of credentials.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.