Check if location is on a toll road

帅比萌擦擦* 提交于 2019-12-24 09:18:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!