如果路线已收到Google地图API xml请求,则返回 [英] Return if route has Tolls Google Maps API xml request
问题描述
在标准Google地图方向搜索中,在写明方向之前已经建议说明此路线已收费。如果没有收费没有咨询节目。我有一个谷歌地图API显示地图的旅行距离和从1个家庭住址到1个工作地址的时间。我很难找到我可以通过xml返回值的路线是否有通行费。在我可以指定的api请求中避免收费,但如果路由上有收费,则不会返回确认。感谢您的帮助。
In the Standard google maps direction search it has advisory before the directions are written stating this route has tolls. If there are no tolls no advisory shows. I have a google maps api request that is displaying the map with travel distance and duration from 1 home address to 1 work address. I am having difficulty finding where I can return a value through xml on whether the route has tolls. In the api request I can specify to avoid tolls but not return a confirmation if there is a toll on the route. Thank you for your help.
推荐答案
应该可以工作,但我并不保证Google会提醒您每条收费公路或不。我认为他们可以,他们的街景汽车已经旅行了他们每一个人,我确信他们知道他们都在哪里。
Should work, but I'm not guaranteeing that google will alert you to every toll road or not. I'd assume they could, their streetview cars having traveled every single one of them I'm sure they do know where they all are.
<?php
$requestUrl = 'http://maps.googleapis.com/maps/api/directions/xml?origin=Milwaukee,WI&destination=Rolling+Meadows,IL&sensor=false';
$response = file_get_contents($requestUrl);
//note I'm assuming English language
$hasTolls = (strpos($response, 'Toll road') !== false);
var_dump($hasTolls);
?>
编辑:
事实上,报告收费公路的数量可能很有用:
In fact, it may be useful to report the number of toll roads:
<?php
$requestUrl = 'http://maps.googleapis.com/maps/api/directions/xml?origin=Milwaukee,WI&destination=Rolling+Meadows,IL&sensor=false';
$response = file_get_contents($requestUrl);
//note I'm assuming English language
$numTolls = substr_count($response, 'Toll road');
$hasTolls = ($numTolls > 0);
var_dump($hasTolls);
if ($hasTolls) {
echo '<p>The route has '.$numTolls.' toll roads</p>';
}
?>
这篇关于如果路线已收到Google地图API xml请求,则返回的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!