Bing Traffic API消失事件,结果波动

时间:2015-06-30 07:34:18

标签: php xml bing-maps bing-api

我正在为该地区的交通事故解析Bing API,我使用了网址

http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?o=xml&severity=3,4&key=#######myapikey######

示例结果是:

<?xml version="1.0" encoding="UTF-8"?>
<Response>
   <Copyright>Copyright © 2015 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.</Copyright>
   <BrandLogoUri>http://dev.virtualearth.net/Branding/logo_powered_by.png</BrandLogoUri>
   <StatusCode>200</StatusCode>
   <StatusDescription>OK</StatusDescription>
   <AuthenticationResultCode>ValidCredentials</AuthenticationResultCode>
   <TraceId>b6b8a1174b3c40738f754f3ed0d443db|BN20130731|02.00.174.2300|BN20010843</TraceId>
   <ResourceSets>
      <ResourceSet>
         <EstimatedTotal>3</EstimatedTotal>
         <Resources>
            <TrafficIncident>
               <Point>
                  <Latitude>38.8677</Latitude>
                  <Longitude>-94.80368</Longitude>
               </Point>
               <Source>4</Source>
               <IncidentId>9000000669</IncidentId>
               <LastModifiedUTC>2015-06-24T15:12:15.0238037Z</LastModifiedUTC>
               <StartTimeUTC>2015-05-20T16:45:09Z</StartTimeUTC>
               <EndTimeUTC>2015-07-10T17:19:00Z</EndTimeUTC>
               <Type>Miscellaneous</Type>
               <Severity>Serious</Severity>
               <Verified>true</Verified>
               <RoadClosed>true</RoadClosed>
               <Description>is closed between I-35 and I-35 - closed</Description>
               <ToPoint>
                  <Latitude>38.8677</Latitude>
                  <Longitude>-94.80368</Longitude>
               </ToPoint>
            </TrafficIncident>
            <TrafficIncident>
               <Point>
                  <Latitude>38.95653</Latitude>
                  <Longitude>-94.74221</Longitude>
               </Point>
               <Source>4</Source>
               <IncidentId>9000000690</IncidentId>
               <LastModifiedUTC>2015-06-24T15:12:15.0238037Z</LastModifiedUTC>
               <StartTimeUTC>2015-05-27T17:08:07Z</StartTimeUTC>
               <EndTimeUTC>2015-10-05T09:04:00Z</EndTimeUTC>
               <Type>Miscellaneous</Type>
               <Severity>Serious</Severity>
               <Verified>true</Verified>
               <RoadClosed>true</RoadClosed>
               <Description>is closed between W 95th St and W 95th St - closed</Description>
               <ToPoint>
                  <Latitude>38.95653</Latitude>
                  <Longitude>-94.74221</Longitude>
               </ToPoint>
            </TrafficIncident>
            <TrafficIncident>
               <Point>
                  <Latitude>38.94201</Latitude>
                  <Longitude>-94.74218</Longitude>
               </Point>
               <Source>4</Source>
               <IncidentId>9000000691</IncidentId>
               <LastModifiedUTC>2015-06-24T15:12:15.0238037Z</LastModifiedUTC>
               <StartTimeUTC>2015-05-27T17:10:13Z</StartTimeUTC>
               <EndTimeUTC>2015-10-05T09:05:00Z</EndTimeUTC>
               <Type>Miscellaneous</Type>
               <Severity>Serious</Severity>
               <Verified>true</Verified>
               <RoadClosed>true</RoadClosed>
               <Description>is closed between W 103rd St and W 103rd St - closed</Description>
               <ToPoint>
                  <Latitude>38.94201</Latitude>
                  <Longitude>-94.74218</Longitude>
               </ToPoint>
            </TrafficIncident>
         </Resources>
      </ResourceSet>
   </ResourceSets>
</Response>

然而结果是波动的,有时我得到5个结果,1秒后2和1秒后再次和之前相同的5个。

此外,这些波动与StartTimeUTC,EndTimeUTC无关,它应指示事件报告有效性的开始和结束。

因为当结果中出现意外时我需要发送警报电子邮件,我当前在APC数组中插入了IncidentId的值,并且只提取那些命中率高的那些并且忽略那些很少出现的那些。

任何人都知道为什么会这样,以及如何有效地解决它?

修改

要加载xml文件,我在PHP5中使用类似的东西:

$xml = simplexml_load_file("http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-105,45,-94?o=xml&severity=3,4&key=#######myapikey######");

我没有看到任何说明如何设置超时的文档,因此我觉得simplexml_load_file()函数应该等待整个xml响应的加载。

0 个答案:

没有答案