Geolocation - Android getting the distance using a Location object

De openkb
Aller à : Navigation, rechercher

Sommaire

Questions

I’d like to take a series of samples of coordinates returned by GPS and calculate the (straight line) distance between them so I can graph the distances via Excel. I see the method distanceBetween and distanceTo of the Location class, but I’m concerned these don’t return the straight line distance.

Does anyone know what distance is returned by these methods or if there are any ways to calculate straight line distance based on latitude/longitude values returned by the Location class?

Answers

A Google search will offer solutions should you somehow desire to do this calculation yourself. For example the Haversine approach:

var R = 6371; // km
var dLat = (lat2-lat1).toRad();
var dLon = (lon2-lon1).toRad(); 
var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
        Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
        Math.sin(dLon/2) * Math.sin(dLon/2); 
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a)); 
var d = R * c;

http://www.movable-type.co.uk/scripts/latlong.html http://www.movable-type.co.uk/scripts/latlong.html

Source

License : cc by-sa 3.0

http://stackoverflow.com/questions/5315015/android-getting-the-distance-using-a-location-object

Related

Outils personnels
Espaces de noms

Variantes
Actions
Navigation
Outils