AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Programmieren allgemein GMLib (Google Map), wer kennt sich aus?
Thema durchsuchen
Ansicht
Themen-Optionen

GMLib (Google Map), wer kennt sich aus?

Ein Thema von SiggiP · begonnen am 8. Nov 2014 · letzter Beitrag vom 25. Mai 2015
 
Benutzerbild von GPRSNerd
GPRSNerd

Registriert seit: 30. Dez 2004
Ort: Ruhrpott
239 Beiträge
 
Delphi 10.4 Sydney
 
#3

AW: GMLib (Google Map), wer kennt sich aus?

  Alt 8. Nov 2014, 18:19
Folgenden Code benutze ich zur Distanzberechnung mittels Haversine-Formel (http://en.wikipedia.org/wiki/Haversine_formula) auf der Erdkugel zwischen zwei GPS-Koordinaten, der ist recht genau:

Delphi-Quellcode:
const
  EarthRadius = 6371.0; //Mean Earth radius in Km
  pi = System.Pi;
  half_pi = pi/2;
  rad = pi/180; //conversion factor for degrees into radians

Function atan2(const y, x: Extended): Extended;
begin
  Result := 0.0; //temp.

  if x = 0.0 then
  begin
    if y = 0.0 then
      raise EMathError.Create('Math Error in atan2: undefined for y=x=0')
    else if y > 0.0 then
      Result := + half_pi
    else
      Result := - half_pi;
  end
  else
  begin
    if x > 0.0 then
        Result := arctan(y/x)
    else if x < 0.0 then
    begin
      if y >= 0.0 then
        Result := arctan(y/x)+pi
      else
        Result := arctan(y/x)-pi;
    end;
  end;
end;

Function CalcDistance(const lonFrom, lonTo, latFrom, latTo: Extended): Extended;
Var
   dlon, dlat, a, c: Extended;
begin
  if ((latFrom = latTo) and (lonFrom = lonTo)) then //Trivialfall, identische Punkte
    Result := 0.0
  else
  begin
    dlon := (lonTo-lonFrom)*rad;
    dlat := (latTo-latFrom)*rad;

    //The Haversine formula
    a:= sqr(sin(dlat/2)) + cos(latFrom*rad) * cos(latTo*rad) * sqr(sin(dlon/2));
    try
      c := 2 * atan2(sqrt(a), sqrt(1-a));
    except
      c := 0;
    end;

    //Distanz/Großkreis auf dem Erdradius
    Result := EarthRadius * c;
  end;
end;
Stefan
  Mit Zitat antworten Zitat
 

 

Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 04:35 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz