2017-04-09 35 views
0

我正在使用Bings交通API來獲取某個位置的流量事件,例如,我想查看加利福尼亞Danville的所有流量事件。但是,他們的API要求傳遞邊界框以獲取我需要的信息。有沒有辦法根據城市/州或郵政編碼等位置找到邊界框?這是網址調用。我更喜歡PHP中的解決方案來獲得邊界框。如何獲取用於Bing Traffic API的位置的邊界框

http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-121,37,-121?key=mybingapicode 
+0

潛在地發現一些PHP工具,可以得到邊界框 – John

+0

http://geocoder-php.org/Geocoder/,https://github.com/thephpleague/geotools,https://github.com/anthonymartin/ GeoLocation.php和http://stackoverflow.com/questions/2628039/php-library-calculate-a-bounding-box-for-a-given-lat-lng-location – John

回答

0

好吧,看起來我再次找到答案。我在這裏找了一個多小時才找到這裏。但最終這裏是解決方案。我需要一個PHP解決方案,可以根據城市/州或郵政編碼獲取位置的邊界框座標。我發現這一點:

http://geocoder-php.org/Geocoder/

我創建的代碼能夠得到基於我指的是位置的邊框。

$curl = new \Ivory\HttpAdapter\CurlHttpAdapter(); 
$geocoder = new \Geocoder\Provider\GoogleMaps($curl); 

$boundry = $geocoder->geocode('Danville, CA')->get(0)->getBounds()->toArray(); 
$north = $boundry['north']; 
$south = $boundry['south']; 
$east = $boundry['east']; 
$west = $boundry['west']; 

我安裝了這個通過作曲家和自動裝載這個類。這是我用來通過作曲家進行安裝:

composer require willdurand/geocoder 

現在我可以動態生成邊界框座標附近的路段和工程就像一個魅力!希望這可以幫助其他人尋找一個簡單易用的PHP解決方案來從一個位置獲得邊界框,這個類還有很多其他的強大功能。