Esempio n. 1
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     $diffLatitude = $from->getLatitude() - $to->getLatitude();
     $diffLongitude = $from->getLongitude() - $to->getLongitude();
     $a = sin($diffLatitude / 2) * sin($diffLatitude / 2) + cos($from->getLatitude()) * cos($to->getLatitude()) * sin($diffLongitude / 2) * sin($diffLongitude / 2);
     $c = 2 * asin(sqrt($a));
     $distance = self::EARTH_RADIUS * $c;
     return $this->createDistance($distance * 1000);
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     $params = array('locations' => array(array('lat' => $from->getLat(), 'lng' => $from->getLng()), array('lat' => $to->getLat(), 'lng' => $to->getLng())));
     $json = $this->getQueryJson($params);
     if (!isset($json)) {
         throw new ProviderError('Wrong json responce');
     }
     if ($json['count'] <= 0) {
         throw new ProviderError('Provider not return distances');
     }
     try {
         $distance = \igorw\get_in($json, ['distances', 0, 'distance']);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }
Esempio n. 3
0
 /**
  * {@inheritDoc}
  */
 public function getDistance(Coordinate $from, Coordinate $to)
 {
     if ($from == $to) {
         return $this->createDistance(0);
     }
     $params = $this->getParams();
     $params['from_point'] = $from->getLat() . ',' . $from->getLng();
     $params['to_point'] = $to->getLat() . ',' . $to->getLng();
     $params['out_array'] = 'distances';
     $json = $this->getQueryJson($params);
     if (!isset($json) || !isset($json['distances'])) {
         throw new ProviderError('Wrong json responce');
     }
     try {
         $distance = \igorw\get_in($json, ['distances', 0, 0]);
     } catch (\InvalidArgumentException $exp) {
         throw new ProviderError('Provider responce format changed');
     }
     return $this->createDistance($distance);
 }