Check if a latitude and longitude is within a circle

前端 未结 6 1719
一整个雨季
一整个雨季 2020-12-04 13:47

See this illustration:

\"enter

What I would like to know is:

  1. How
6条回答
  •  孤街浪徒
    2020-12-04 14:18

    Location didn't work for me, here's what I did.

    import 'dart:math' show cos, sqrt, asin;
    
    
    double calculateDistanceBetweenTwoLatLongsInKm(
        double lat1, double lon1, double lat2, double lon2) {
      var p = 0.017453292519943295;
      var c = cos;
      var a = 0.5 -
          c((lat2 - lat1) * p) / 2 +
          c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p)) / 2;
      return 12742 * asin(sqrt(a));
    }
    

    Then just check if that distance is more (outside) or less (inside) than your radius in KM

提交回复
热议问题