且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

通过Web服务访问Google的流量数据

更新时间:2023-12-02 10:48:16

(或者至少没有合理简单便捷的方式)从Google Maps Javascript API v3获取原始流量数据。即使您可以这样做,也可能违反Google地图服务条款中的某些条款。你将不得不从另一个服务获取这些信息。我怀疑目前有免费服务提供这些信息,但如果有人证明我错了,我会很喜欢它。

正如@crdzoba指出的那样, Bing Maps API公开一些流量数据。也许这可以满足你的需求。从文档中不清楚有多少流量数据暴露出来,因为它只是关于事件的数据。由于建设缓慢的交通将在那里,但它对我来说是不是很明显是否由于交通量的减少而导致交通量减少。

更新(2016年3月):有很多因为这个答案是在2011年编写的,但核心点似乎仍然存在:您在免费 API服务中找不到原始流量数据(至少不是美国,可能不是大多数其他地方)。但是,如果您不介意支付一点费用和/或如果您只需要诸如考虑流量的特定路线的行程时间等事项,则可以选择。例如, @ Anto的回答指向 Google的Maps for Work 作为付费API服务,可让您将旅行时间考虑在流量中。


Is there a way I can access traffic data that Google provides through a web service?

There seems to be a GTrafficOverlay that puts traffic on top of a route on an embedded google map, but no direct web service that I can consume to, say, give the source and the destination and find the traffic between them?

Is there any other source I can get this data from?

There is no way (or at least no reasonably easy and convenient way) to get the raw traffic data from Google Maps Javascript API v3. Even if you could do it, doing so is likely to violate some clause in the Terms Of Service for Google Maps. You would have to get this information from another service. I doubt there is a free service that provides this information at the current time, but I would love it if someone proved me wrong on that.

As @crdzoba points out, Bing Maps API exposes some traffic data. Perhaps that can fill your needs. It's not clear from the documentation how much traffic data that exposes as it's only data about "incidents". Slow traffic due to construction would be in there, but it's not obvious to me whether slow traffic due simply to volume would be.

UPDATE (March 2016): A lot has happened since this answer was written in 2011, but the core points appear to hold up: You won't find raw traffic data in free API services (at least not for the U.S., and probably not most other places). But if you don't mind paying a bit and/or if you just need things like "travel time for a specific route taking traffic into consideration" you have options. @Anto's answer, for example, points to Google's Maps For Work as a paid API service that allows you to get travel times taking traffic into consideration.