Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distance between two points #996

Open
Zokirjon-Ashiraliyev opened this issue Oct 1, 2024 · 1 comment
Open

Distance between two points #996

Zokirjon-Ashiraliyev opened this issue Oct 1, 2024 · 1 comment

Comments

@Zokirjon-Ashiraliyev
Copy link

How can i calculate disantance between two points. Are there some methods in Location data classes ?

@xunreal75
Copy link

It's not a topic or bug of this package.

Use a haversine method

 /// Calculate between two locations in meter
  static double haversine(double lat1, double lon1, double lat2, double lon2) {
    // distance between latitudes and longitudes
    double dLat = radians(lat2 - lat1);
    double dLon = radians(lon2 - lon1);
    // convert to radians
    lat1 = radians(lat1);
    lat2 = radians(lat2); // apply formulae
    var a =
        pow(sin(dLat / 2), 2) + pow(sin(dLon / 2), 2) * cos(lat1) * cos(lat2);
    double rad = 6371;
    double c = 2 * asin(sqrt(a));
    return rad * c*1000;
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants