0

I am using Bings traffic API to grab traffic incidents for a location, for example I want to see all traffic incidents in Danville, CA. However their API requires the bounding box to be passed in order to get the information I need. Is there a way to find the bounding box based on a location like city/state or zip code? Here is the url call. I prefer the solution be in PHP to get the bounding box.

http://dev.virtualearth.net/REST/v1/Traffic/Incidents/37,-121,37,-121?key=mybingapicode
John
  • 9,840
  • 26
  • 91
  • 137
  • Potentially found some php tools that can get the bounding box – John Apr 09 '17 at 02:02
  • http://geocoder-php.org/Geocoder/ , https://github.com/thephpleague/geotools , https://github.com/anthonymartin/GeoLocation.php and http://stackoverflow.com/questions/2628039/php-library-calculate-a-bounding-box-for-a-given-lat-lng-location – John Apr 09 '17 at 02:03

1 Answers1

0

Ok looks like I found the answer again. I looked for over an hour before posting here. But eventually here is the solution. I needed a PHP solution that could get the bounding box coordinates for a location based on either city/state or zip code. I found this:

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

The code I created was able to get the bounding box based on the location I was referring to.

$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'];

I installed this via composer and autoloaded this class. This is what I used to install it via composer:

composer require willdurand/geocoder

Now I can dynamically generate the link with the bounding box coordinates and works like a charm! Hope this helps anyone else looking for an easy to use PHP solution to get the bounding box from a location, this class also has a lot of other great features as well.

John
  • 9,840
  • 26
  • 91
  • 137