/** * Looks up the geo coordinates of the address of an object and sets its * geo coordinates. * * @param tx_oelib_Interface_Geo $geoObject * the object for which the geo coordinates will be looked up and set * * @return void */ public function lookUp(tx_oelib_Interface_Geo $geoObject) { if ($geoObject->hasGeoError() || $geoObject->hasGeoCoordinates()) { return; } if (!$geoObject->hasGeoAddress()) { $geoObject->setGeoError(); return; } if (!empty($this->coordinates)) { $geoObject->setGeoCoordinates($this->coordinates); } else { $geoObject->setGeoError(); } }
/** * Looks up the geo coordinates of the address of an object and sets its * geo coordinates. * * @param tx_oelib_Interface_Geo $geoObject * the object for which the geo coordinates will be looked up and set * * @return void */ public function lookUp(tx_oelib_Interface_Geo $geoObject) { if ($geoObject->hasGeoError() || $geoObject->hasGeoCoordinates()) { return; } if (!$geoObject->hasGeoAddress()) { $geoObject->setGeoError(); return; } $address = $geoObject->getGeoAddress(); $this->throttle(); $rawResult = $this->sendRequest($address); if ($rawResult === FALSE) { throw new RuntimeException('There was an error connecting to the Google geocoding server.', 1331488446); } $resultParts = json_decode($rawResult, TRUE); $status = $resultParts['status']; if ($status === self::STATUS_OK) { $coordinates = $resultParts['results'][0]['geometry']['location']; $geoObject->setGeoCoordinates(array('latitude' => (double) $coordinates['lat'], 'longitude' => (double) $coordinates['lng'])); } else { $geoObject->setGeoError(); } }
/** * Moves $object by $distance kilometers in the direction of $direction. * * Note: This move is not very accurate. * * @param tx_oelib_Interface_Geo $object * @param float $direction direction of the movement in degrees (0.0 is east) * @param float $distance distance to move in kilometers, may be positive, zero or negative * * @return void */ public function move(tx_oelib_Interface_Geo $object, $direction, $distance) { $directionInRadians = deg2rad($direction); $originalCoordinates = $object->getGeoCoordinates(); /** @var float $originalLatitude */ $originalLatitude = $originalCoordinates['latitude']; /** @var float $originalLongitude */ $originalLongitude = $originalCoordinates['longitude']; $xDeltaInKilometers = $distance * cos($directionInRadians); $yDeltaInKilometers = $distance * sin($directionInRadians); $oneDegreeLongitudeInKilometers = 2 * M_PI * self::EARTH_RADIUS_IN_KILOMETERS * cos($originalLongitude) / 360; $latitudeDelta = $yDeltaInKilometers / self::ONE_DEGREE_LATITUDE_IN_KILOMETERS; $longitudeDelta = $xDeltaInKilometers / $oneDegreeLongitudeInKilometers; $object->setGeoCoordinates(array('latitude' => $originalLatitude + $latitudeDelta, 'longitude' => $originalLongitude + $longitudeDelta)); }