public function get_distance_to(lat_lng $other) { $x = $this->sin_lat() * $other->sin_lat() + $this->cos_lat() * $other->cos_lat() * cos($this->lng(true) - $other->lng(true)); if (!is_nan($acos = acos($x))) { return $acos * 6371; } else { return 0; } }