質問

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?

役に立ちましたか?

解決

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

他のヒント

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top