Question: In Java on Android Studio, I have two locations from the map and their coordinates. I need to find the time the user has been

In Java on Android Studio, I have two locations from the map and their coordinates. I need to find the time the user has been traveling between the two locations. I have the following method to calculate time. Is this method right or how can I make it better? If it is wrong, how can I modify the code to give the approximate time?

public String getTimeTaken(Location source, Location dest) { double meter = source.distanceTo(dest); double kms = meter / 1000; double kms_per_min = 0.5; double mins_taken = kms / kms_per_min; int totalMinutes = (int) mins_taken; if (totalMinutes<60) { return ""+totalMinutes+" mins"; }else { String minutes = Integer.toString(totalMinutes % 60); minutes = minutes.length() == 1 ? "0" + minutes : minutes; return (totalMinutes / 60) + " hour " + minutes +"mins"; } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!