Frage

I have location of user(class Location). And list of GeoPoints. Is it some function to calculate distance? Or write own function it is the only solution?

War es hilfreich?

Lösung

I believe the easiest way would be to use the distanceBetween function in the Android Location class.

Location userLocation = new Location();
GeoPoint geoPoint = new GeoPoint();
float[] results = new float[3];
Location.distanceBetween(userLocation.getLatitude(), userLocation.getLongitude(), (geoPoint.getLatitudeE6()/1E6), (geoPoint.getLongitudeE6()/1E6), results); 
//result[0] = distance in m

Andere Tipps

This is a simple math equation. See Euclidean Distance

Ensure that your units make sense. If there is not a library function to perform this, the coding is completely trivial.

Openmap is a library to build applications with maps. It has classes and methods for distance and azimuth calculation between two points. See class Geo.

If the library is too big, you can download sources from svn and copy only the class Geo and its dependencies.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top