Using the Bing Maps Web Services in PHP

·
<?php
class BingMaps {
  // get an application key from https://www.bingmapsportal.com/application/
  private $key = 'YOUR-APPLICATION-KEY';
  private $server = 'http://dev.virtualearth.net/webservices/v1';
  
  function geocode($query, $n = 1){
    $client = new SoapClient($this->server . '/geocodeservice/geocodeservice.svc?wsdl');
    $request = $this->request($query, $n);
    $result = $client->Geocode($request);
    return $result->GeocodeResult->Results->GeocodeResult;
  }
  function search($query, $n = 10){
    $client = new SoapClient($this->server . '/searchservice/searchservice.svc?wsdl');
    $request = $this->request($query, $n);
    $result = $client->Search($request);
    return $result->SearchResult->ResultSets->SearchResultSet->Results->SearchResultBase;
  }
  private function request($query, $n){
    return array('request' => array(
      'Credentials' => array('ApplicationId' => $this->key),
      'Query' => $query,
      'Options' => array('Count' => $n),
    ));
  }
}
/* example usage */
$api = new BingMaps();
$result = $api->geocode('1 Microsoft Way, Redmond, WA, United States');
print_r($result);
$api = new BingMaps();
$result = $api->search('Microsoft in Redmond');
print_r($result);

Microsoft's "documentation".