I'm trying to learn new things and decided as a project to make an
application for recording data from running. I've got a rough
calculation of my distance on runs, but am trying to get it more
accurate. I was hoping someone might have some ideas. Right now I'm
simply accepting gps fixes and then using the distance formula on the
fixes in a sequential order to determine how far I've ran. I'm hoping
however to get the distance more accurate and save battery life. If
anyone has any idea on how I can improve the method I'm using now I
would love to discuss it.
public void onLocationChanged(Location
location) {
if(location != null) {
if(gpsLats.size() >= 1)
{
//add new gps
info to List
gpsLats.add(location.getLatitude());
gpsLongs.add(location.getLongitude());
//create new
location and store previous gps coordinates
Location loc =
new Location(location);
loc.setLatitude(gpsLats.get(gpsLats.size()-2));
loc.setLongitude(gpsLongs.get(gpsLats.size()-2));
//find distance
traveled
tmpDistance +=
loc.distanceTo(location)*0.000621371192;
} else {
// add first
gps coordinates to List and append to list
gpsLats.add(location.getLatitude());
gpsLongs.add(location.getLongitude());
}
} else {
mSB.append("Location
can not be found!");
}
tv2.setText("Distance: " +
Double.toString(tmpDistance) + "
miles");
tv.setText(mSB.toString());
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en