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

后端 未结 5 1062
悲哀的现实
悲哀的现实 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:04

       Calculate Distance:-
        float distance;
                Location locationA=new Location("A");
                locationA.setLatitude(lat);
                locationA.setLongitude(lng);
    
                Location locationB = new Location("B");
                locationB.setLatitude(lat);
                locationB.setLongitude(lng);
    
                distance = locationA.distanceTo(locationB)/1000;
    
                LatLng From = new LatLng(lat,lng);
                LatLng To = new LatLng(lat,lng);
    
                Calculate Time:-
                int speedIs1KmMinute = 100;
                float estimatedDriveTimeInMinutes = distance / speedIs1KmMinute;
                   Toast.makeText(this,String.valueOf(distance+
    "Km"),Toast.LENGTH_SHORT).show();
                Toast.makeText(this,String.valueOf(estimatedDriveTimeInMinutes+" Time"),Toast.LENGTH_SHORT).show();
    

提交回复
热议问题