问题
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
回答1:
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.
来源:https://stackoverflow.com/questions/43089624/check-if-location-is-on-a-toll-road