Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP][inne][MySQL]GPS i koordynaty
Forum PHP.pl > Forum > Przedszkole
Skorpiono
Witam, wlasnie po latach przerwy w programowaniu zaczalem pisac apke na komorke i musze zamienic koordynaty GPS wgs84 na metry, ktos z was zna przelicznik?
Rysh
Nie wiem co to ma wspólnego z PHP i MySQL ale znalazłem coś takiego:
http://gis.stackexchange.com/questions/865...itude/8674#8674
Skorpiono
dzieki tego szukalem, ale mam jeszcze

Haversine
formula: a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)
c = 2 ⋅ atan2( √a, √(1−a) )
d = R ⋅ c
oblicza mi metry

umial by ktos to napisac w php?
Rysh
Kolega ma chyba problem z szukaniem.
https://rosettacode.org/wiki/Haversine_formula#PHP
  1. class POI {
  2. private $latitude;
  3. private $longitude;
  4. public function __construct($latitude, $longitude) {
  5. $this->latitude = deg2rad($latitude);
  6. $this->longitude = deg2rad($longitude);
  7. }
  8. public function getLatitude() return $this->latitude;
  9. public function getLongitude() return $this->longitude;
  10. public function getDistanceInMetersTo(POI $other) {
  11. $radiusOfEarth = 6371000;// Earth's radius in meters.
  12. $diffLatitude = $other->getLatitude() - $this->latitude;
  13. $diffLongitude = $other->getLongitude() - $this->longitude;
  14. $a = sin($diffLatitude / 2) * sin($diffLatitude / 2) +
  15. cos($this->latitude) * cos($other->getLatitude()) *
  16. sin($diffLongitude / 2) * sin($diffLongitude / 2);
  17. $c = 2 * asin(sqrt($a));
  18. $distance = $radiusOfEarth * $c;
  19. return $distance;
  20. }
  21. }

  1. $user = new POI($_GET["latitude"], $_GET["longitude"]);
  2. $poi = new POI(19,69276, -98,84350); // Piramide del Sol, Mexico
  3. echo $user->getDistanceInMetersTo($poi);
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.