- 回答,见下文 -
如何从Bing Routes API响应中访问并回显行程距离金额?
有很多关于XML的教程:http://www.php.net/manual/en/simplexml.examples-basic.php
以下是响应示例(行程距离靠近底部): https://msdn.microsoft.com/en-us/library/gg636957.aspx
以下是调用响应并检索行程距离的代码示例。
$calculateURL = $drivingRoutesBaseURL."?wayPoint.1=".$waypoint1."&wayPoint.2=".$waypoint2."&output=xml&key=".$bingKey;
//发送请求 //从Locations API获取响应并将其存储在字符串
中$output = file_get_contents($calculateURL);
//基于XML字符串
创建XML元素$response = new SimpleXMLElement($output);
//从响应中获取行程距离元素
$travelDistance = $response->ResourceSets->ResourceSet->Resources->Route->TravelDistance;
echo $travelDistance;
答案 0 :(得分:0)
此行返回具有行进距离的对象。
$travelDistance = $response->ResourceSets->ResourceSet->Resources->Route->TravelDistance;
echo $travelDistance;