is there any formula to get travel time between two locations or from distance in flutter without using google maps

1.6k views Asked by At

I have two locations and I have the formula to get the distance between them but I want to calculate the travel time between them without using google maps or any API calling. Is there any formula to do that in flutter?

2

There are 2 answers

6
L. Gangemi On

I think the real travel time depends on a lot of factors, for example the road you take or the speed limit.

Whitout some complex elaboration, which are usually perfomed by a backend, I don't think it is possible to calculate it.

Anyway, since you have got the distance, you could simply estimate it by giving a supposed speed and then using basic physics formulas.

time = distance / speed.

2
Muhammad Tameem Rafay On

You cannot find the travel distance between two locations without using the Google API. However you can get the air distance in meters using this formula in flutter.

double calculateDistance(
      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;
    var temp = 12742 * asin(sqrt(a));
    return (temp * 1000);
  }