Distance calculation done simply

Actions & Logic

I´ve just switched my distance calculation to using the geolocation function. Much simpler than the formulas, so thought I would share it.

import 'package:geolocator/geolocator.dart';
import 'package:device_info_plus/device_info_plus.dart';
import 'package:universal_io/io.dart';
import 'dart:math';

Future<double> calculateDistance(
  double? lat1,
  double? lon1,
  double? lat2,
  double? lon2,
) async {
  if (lat1 == null || lon1 == null || lat2 == null || lon2 == null) {
    return 99;
  } else {
    double distanceInMeters =
        Geolocator.distanceBetween(lat1!, lon1!, lat2!, lon2!);
    return distanceInMeters;
  }
}
What have you tried so far?

NA

Did you check FlutterFlow's Documentation for this topic?
No
2
2 replies