/** * Returns the geographical distance between two coordinates. * See http://en.wikipedia.org/wiki/Geographical_distance * * @since 2.0 * * @param LatLongValue $start * @param LatLongValue $end * * @return float Distance in m. */ public static function calculateDistance(LatLongValue $start, LatLongValue $end) { $northRad1 = deg2rad($start->getLatitude()); $eastRad1 = deg2rad($start->getLongitude()); $cosNorth1 = cos($northRad1); $cosEast1 = cos($eastRad1); $sinNorth1 = sin($northRad1); $sinEast1 = sin($eastRad1); $northRad2 = deg2rad($end->getLatitude()); $eastRad2 = deg2rad($end->getLongitude()); $cosNorth2 = cos($northRad2); $cosEast2 = cos($eastRad2); $sinNorth2 = sin($northRad2); $sinEast2 = sin($eastRad2); $term1 = $cosNorth1 * $sinEast1 - $cosNorth2 * $sinEast2; $term2 = $cosNorth1 * $cosEast1 - $cosNorth2 * $cosEast2; $term3 = $sinNorth1 - $sinNorth2; $distThruSquared = $term1 * $term1 + $term2 * $term2 + $term3 * $term3; $distance = 2 * Maps_EARTH_RADIUS * asin(sqrt($distThruSquared) / 2); assert($distance >= 0); return $distance; }
/** * Returns an object that can directly be converted to JS using json_encode or similar. * * FIXME: complexity * * @since 1.0 * * @param string $defText * @param string $defTitle * @param string $defIconUrl * @param string $defGroup * @param string $defInlineLabel * @param string $defVisitedIcon * * @return array */ public function getJSONObject($defText = '', $defTitle = '', $defIconUrl = '', $defGroup = '', $defInlineLabel = '', $defVisitedIcon = '') { $parentArray = parent::getJSONObject($defText, $defTitle); $array = array('lat' => $this->coordinates->getLatitude(), 'lon' => $this->coordinates->getLongitude(), 'alt' => 0, 'address' => $this->getAddress(false), 'icon' => $this->hasIcon() ? \MapsMapper::getFileUrl($this->getIcon()) : $defIconUrl, 'group' => $this->hasGroup() ? $this->getGroup() : $defGroup, 'inlineLabel' => $this->hasInlineLabel() ? $this->getInlineLabel() : $defInlineLabel, 'visitedicon' => $this->hasVisitedIcon() ? $this->getVisitedIcon() : $defVisitedIcon); return array_merge($parentArray, $array); }