Question

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?

Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top