please shed some light on this situation
Right now i have two array having latitude and longitude of nearby places and also have the user location latiude and longiude now i want to calculate the distance between user location and nearby places and want to show them in listview.
I know that there is a method for calculating distance as
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results);
Now what is the problem is how to pass these two array having nearby latitude and longitue in this method and get the array of distances.
distanceTo will give you the distance in meters between the two given location ej target.distanceTo(destination).
distanceBetween give you the distance also but it will store the distance in a array of float( results[0]). the doc says If results has length 2 or greater, the initial bearing is stored in results[1]. If results has length 3 or greater, the final bearing is stored in results[2]
hope that this helps
i've used distanceTo to get the distance from point A to B i think that is the way to go.
Try This Code. here we have two longitude and latitude values and selected_location.distanceTo(near_locations) function returns the distance between those places in meters.
here "distance" is distance between locationA & locationB (in Meters)
There is only one user Location, so you can iterate List of nearby places can call the
distanceTo()
function to get the distance, you can store in an array if you like.From what I understand,
distanceBetween()
is for far away places, it's output is a WGS84 ellipsoid.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:
or