Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started