1

I am working on a shipment system and in order to calculate the charge for a shipment I need to know if the driver whas in a toll road during the job so I can add the charge to the shipment.

I get the location of the driver all the time from an android/ios app he is using.

My question is:
Is there a way to send a location (latitude & longitude) to google maps api and get back an answere if the location is on a toll road.

Thank you

Dushy
  • 375
  • 3
  • 13

1 Answers1

4

Well, there is no API for this particular request, that u send a location and give you true/false for toll!

but you can do one thing, usually when road have toll, in html_instructions of the response, there is "toll road" string. so what you can do is to send the location and get the response, and search for "toll road" in the response. if exist, that mean the location have toll!

I write a example code for you :

$.get(
"https://maps.googleapis.com/maps/api/directions/json?origin=Milwaukee,WI&destination=Rolling+Meadows,IL&key=YOURAPIKEY",

function(data) {
   var routes = JSON.stringify(data.routes);
   var isToll = routes.search("toll road");
   if(isToll===-1){
    return false;
   }
   else{        
   return true;
   }
}
);

Remember to replace your API KEY in the URL.

Emad Dehnavi
  • 3,262
  • 4
  • 19
  • 44
  • Hi, thank you for the quick response, but I don't have origin and destination locations, I only have the current position of the driver so what do I need to send to the API? – Dushy Mar 29 '17 at 11:08
  • OK if I send the same location on origin and destination it works – Dushy Mar 29 '17 at 11:16