/**
  * {@inheritDoc}
  */
 public function getDistance(CoordinatesInterface $from, CoordinatesInterface $to)
 {
     /* script founded here :
          http://www.phpsources.org/scripts459-PHP.htm
        */
     $rlo1 = deg2rad($from->getLongitude());
     $rla1 = deg2rad($from->getLatitude());
     $rlo2 = deg2rad($to->getLongitude());
     $rla2 = deg2rad($to->getLatitude());
     $dlo = ($rlo2 - $rlo1) / 2;
     $dla = ($rla2 - $rla1) / 2;
     $a = sin($dla) * sin($dla) + cos($rla1) * cos($rla2) * (sin($dlo) * sin($dlo));
     $d = 2 * atan2(sqrt($a), sqrt(1 - $a));
     return round(self::EARTH_RADIUS * $d / 1000, 3);
 }
 /**
  * {@inheritDoc}
  */
 public function populateCoordinates(CoordinatesInterface $coordinates, array $data)
 {
     list($latitude, $longitude) = $data['resourceSets'][0]['resources'][0]['point']['coordinates'];
     return $coordinates->setLatitude($latitude)->setLongitude($longitude);
 }
 /**
  * {@inheritDoc}
  */
 public function getAddress(CoordinatesInterface $coordinates)
 {
     $address = $this->populate(Hydrator::TYPE_ADDRESS, $this->client->get(sprintf('%s/reverse?&callback=renderReverse&outFormat=json&location=%d,%d&key=%s', $this->api_endpoint, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->api_key))->send()->json());
     $this->logger->debug('Locate address by coordinates', array('provider' => 'mapquest', 'address' => $address->getFullAddress(), 'latitude' => $coordinates->getLatitude(), 'longitude' => $coordinates->getLongitude()));
     return $address;
 }
 /**
  * {@inheritDoc}
  */
 public function populateCoordinates(CoordinatesInterface $coordinates, array $data)
 {
     $lnglat = explode(' ', $data['GeoObject']['Point']['pos']);
     return $coordinates->setLatitude($lnglat[1])->setLongitude($lnglat[0]);
 }
 /**
  * {@inheritDoc}
  */
 public function populateCoordinates(CoordinatesInterface $coordinates, array $data)
 {
     $navigationPositions = $data[0]['Result'][0]['Location']['NavigationPosition'][0];
     return $coordinates->setLatitude($navigationPositions['Latitude'])->setLongitude($navigationPositions['Longitude']);
 }
 /**
  * {@inheritDoc}
  */
 public function populateCoordinates(CoordinatesInterface $coordinates, array $data)
 {
     return $coordinates->setLatitude($data[0]['locations'][0]['latLng']['lat'])->setLongitude($data[0]['locations'][0]['latLng']['lng']);
 }
 /**
  * {@inheritDoc}
  *
  * @link http://msdn.microsoft.com/en-us/library/ff701710.aspx
  */
 public function getAddress(CoordinatesInterface $coordinates)
 {
     $address = $this->hydrator->hydrate($this->client->get(sprintf('%s%d,%d?o=json&key=%s', $this->api_endpoint, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->api_key))->send()->json(), Hydrator::TYPE_ADDRESS);
     $this->logger->debug('Locate address by coordinates', array('provider' => 'bing', 'address' => $address->getFullAddress(), 'latitude' => $coordinates->getLatitude(), 'longitude' => $coordinates->getLongitude()));
     return $address;
 }
 /**
  * {@inheritDoc}
  */
 public function getAddress(CoordinatesInterface $coordinates)
 {
     $address = $this->populate(Hydrator::TYPE_ADDRESS, $this->client->get(sprintf('%s?prox=%d,%d&mode=retrieveAddresses&app_id=%s&app_code=%s&gen=8maxresults=1', $this->api_reverse_endpoint, $coordinates->getLatitude(), $coordinates->getLongitude(), $this->app_id, $this->app_code))->send()->json());
     $this->logger->debug('Locate address by coordinates', array('provider' => 'heredotcom', 'address' => $address->getFullAddress(), 'latitude' => $coordinates->getLatitude(), 'longitude' => $coordinates->getLongitude()));
     return $address;
 }
 /**
  * {@inheritDoc}
  */
 public function getAddress(CoordinatesInterface $coordinates)
 {
     $address = $this->populate(Hydrator::TYPE_ADDRESS, $this->client->get(sprintf('%s/?geocode=%d,%d&lang=en-US&format=json&results=1', $this->api_endpoint, $coordinates->getLatitude(), $coordinates->getLongitude()))->send()->json());
     $this->logger->debug('Locate address by coordinates', array('provider' => 'mapquest', 'address' => $address->getFullAddress(), 'latitude' => $coordinates->getLatitude(), 'longitude' => $coordinates->getLongitude()));
     return $address;
 }
 /**
  * {@inheritDoc}
  */
 public function getAddress(CoordinatesInterface $coordinates)
 {
     $address = $this->populate(Hydrator::TYPE_ADDRESS, $this->client->get(sprintf('%sreverse?format=json&lat=%d&lon=%d', $this->api_endpoint, $coordinates->getLatitude(), $coordinates->getLongitude()))->send()->json());
     $this->logger->debug('Locate address by coordinates', array('provider' => 'nominatim', 'address' => $address->getFullAddress(), 'latitude' => $coordinates->getLatitude(), 'longitude' => $coordinates->getLongitude()));
     return $address;
 }