Good day, I want to do findapp in flutter. Help please with decide calculate distance between points.

I found this code

It decision for two points.

But I need use circle - in my firebase coordinates of many object - about 200. I want show to user 3 nearest objects from these. How I need to do it correct? Thank You

``````import 'dart:math' show cos, sqrt, asin;

void main() {
double calculateDistance(lat1, lon1, lat2, 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));
}
double totalDistance = calculateDistance(26.196435, 78.197535,26.197195, 78.196408);
print(totalDistance);
}
``````

### Solution 1: Pankaj Nikam

You can use the method from the geolocator package:

Like this:

``````import 'package:geolocator/geolocator.dart';
double distanceInMeters = await Geolocator().distanceBetween(52.2165157, 6.9437819, 52.3546274, 4.8285838);
``````

Reference:

https://pub.dev/packages/geolocator#calculate-distance

## Most Viewed #### How to debug multiple widgets used the same GlobalKey 