我有波纹管API endpoints 来查找两个位置之间的路由,
https://maps.googleapis.com/maps/api/directions/json?origin=Brooklyn&destination=Queens&mode=driving
这很完美,但我有一组以上的原点和目的地
origin1 to destination1
origin2 to destination2
origin2 to destination2
originn to destinationn
我需要同时获取路由,但Google会在几次请求后阻止来自同一IP的连续请求 . 我的问题是,是否有任何逻辑或方法可用于在Google的单个请求中查找路由集?
1 回答
Google Directions API网络服务不支持多个来源和目的地 . 您只能发送一个源和一个目标的请求,实际上您应该遵守文档中 Build 的允许的每秒查询数(QPS)限制:
https://developers.google.com/maps/documentation/directions/usage-limits
GitHub上有几个库可以实现限制逻辑以保持在允许的限制范围内 . 您可以找到Java,Python,Go和NodeJs的库:
https://github.com/googlemaps/google-maps-services-python
https://github.com/googlemaps/google-maps-services-java
https://github.com/googlemaps/google-maps-services-go
https://github.com/googlemaps/google-maps-services-js
此外,我注意到Google拒绝了尝试为Web服务请求批处理功能的尝试 . 您可以将此功能请求视为参考:
https://issuetracker.google.com/issues/35818254