views:

478

answers:

2

Hi,

I want to make a apps that check what's the nearest place from where the user is. I can easily get the location of the user and I have a list of places with latitude and longitude.

What would be the best way to know the nearest place of the list against the current position.

I could not find anything in the google APIs.

I am worried I need to resort to my calculate and have to do math to calculate it.

What do you guys think ?

Cheers and thanks for reading or replying.

+3  A: 

http://developer.android.com/reference/android/location/Location.html

Look into distanceTo or distanceBetween. You can create a Location object from a latitude and longitude:

Location location = new Location("");
location.setLatitude(lat);
location.setLongitude(lon);
haseman
+1  A: 

There are a couple of methods you could use, but to determine which one is best we first need to know if you are aware of the user's altitude, as well as the altitude of the other points?

Depending on the level of accuracy you are after, you could look into either the Haversine or Vincenty formulae...

These pages detail the formulae, and, for the less mathematically inclined also provide an explanation of how to implement them in script!

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

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

If you have any problems with any of the meanings in the formulae, just comment and I'll do my best to answer them :)

Dwaine Bailey