Android - How to get estimated drive time from one place to another?

后端 未结 5 1072
悲哀的现实
悲哀的现实 2020-12-04 18:25

I need to find the estimate drive time from one place to another. I\'ve got latitudes and longitudes for both places but I have no idea how to do that. Is there is any API f

5条回答
  •  难免孤独
    2020-12-04 19:03

        Location location1 = new Location("");
        location1.setLatitude(lat);
        location1.setLongitude(long);
    
        Location location2 = new Location("");
        location2.setLatitude(lat);
        location2.setLongitude(long);
    
        float distanceInMeters = location1.distanceTo(location2);
    

    EDIT :

        //For example spead is 10 meters per minute.
        int speedIs10MetersPerMinute = 10;
        float estimatedDriveTimeInMinutes = distanceInMeters / speedIs10MetersPerMinute;
    

    Please also see this, if above not works for you:

    Calculate distance between two points in google maps V3

提交回复
热议问题