1

Good day to you programmer! As i have dart code for driver to update realtime location in firebase Firestone is there is a way so using user current location and database location i will find minimum time and distance and route for user end.

    _getLocation() async {
try {
  final loc.LocationData _locationResult = await location.getLocation();
  await FirebaseFirestore.instance.collection('location').doc('${widget.title}').set({
    'latitude': _locationResult.latitude,
    'longitude': _locationResult.longitude,
    'name': '${widget.title}'
  }, SetOptions(merge: true));
} catch (e) {
  print(e);
}

}

  • This function will only collect the coordinates, which you can further use later to calculate the distances+durations. But this function itself will not calculate anything. – Huthaifa Muayyad Jun 08 '22 at 09:32
  • thanks for your valuable response you are right exactly i want to know the dart code to calculate distance and duration. – Zaryab Khalid Jun 08 '22 at 09:48
  • To calculate distance, you need to have two coordinates `2 x (Lat, Lng)`. There are plenty of formulas online to calcualte distance between two points. – Huthaifa Muayyad Jun 08 '22 at 10:07

0 Answers0