Wednesday, September 25, 2013

[android help] Is there any way to calculate speed of current ride in Android Maps V2


Is there any way to calculate speed of current ride in Android Maps V2



Check below code, done by me, and its working well. In this lots of code related your stuff, because I have did exactly same as your requirement. So you can use all the code given below. And if you find it unncessory, then dont use it.



@Override
public void onLocationChanged(Location location) {

try {
if (location != null) {

if (current_lat != null && current_lat > 0) {
latitude = current_lat;
}
if (current_long != null && current_long > 0) {
longitude = current_long;
}
current_lat = location.getLatitude();
current_long = location.getLongitude();
distanceBetweenTwoPoint = getDistance(latitude, longitude, current_lat, current_long);
if ((current_lat > 0 && current_long > 0) && distanceBetweenTwoPoint > IjoomerApplicationConfiguration.track_DistanceBetweenPoints_IN_METERS) {
if (location.hasSpeed()) {
speedInKm = location.getSpeed() * 3.6;
} else {
speedInKm = 0.0;
}
row = new HashMap();
row.put(TRACKID, IN_TRACKID + "");
row.put(LATITUDE, current_lat.toString());
row.put(LONGITUDE, current_long.toString());
row.put(SPEED, speedInKm + "");
row.put(TIMESTAMP, System.currentTimeMillis() + "");
row.put(STATUS, status);

distance = distance + (distanceBetweenTwoPoint / 1000);
row.put(DISTANCE, "" + distance);
dataProvider.InsertRow("TrackDetail", row);
row.put(LASTKNOWNLATITUDE, latitude.toString());
row.put(LASTKNOWNLONGITUDE, longitude.toString());
int seconds = (int) ((System.currentTimeMillis() - trackStartTime) / 1000) % 60;
int minutes = (int) (((System.currentTimeMillis() - trackStartTime) / (1000 * 60)) % 60);
int hours = (int) (((System.currentTimeMillis() - trackStartTime) / (1000 * 60 * 60)) % 24);

row.put(DURATION, String.valueOf(hours) + " : " + String.valueOf(minutes) + " : " + String.valueOf(seconds));
setNotification(speedInKm, String.valueOf(hours) + " : " + String.valueOf(minutes) + " : " + String.valueOf(seconds));
if (status.equalsIgnoreCase("1")) {

builder.append("|" + current_lat + "," + current_long);
trackDuration = String.valueOf(hours) + " : " + String.valueOf(minutes) + " : " + String.valueOf(seconds);
if (speedInKm > maxSpeed) {
maxSpeed = speedInKm;
}
totalSpeed = totalSpeed + speedInKm;
++totalTrackPoint;
sendBrodcastToActivity();
}
}
}
} catch (Exception e) {
e.printStackTrace();
}

}


Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...