I have a program in which latitude and longitude values of a location are stored in a database, which I download.
I want to get the distance between these coordinat
Assuming that you already have a location object with you current location.
Location targetLocation = new Location("");//provider name is unnecessary
targetLocation.setLatitude(0.0d);//your coords of course
targetLocation.setLongitude(0.0d);
float distanceInMeters = targetLocation.distanceTo(myLocation);
You may create locations using their constructor, then set the latutude and longitude values.
final Location location = new Location("yourprovidername");
location.setLatitude(1.2345d);
location.setLongitude(1.2345d);
I am answering this again, because lot of people like me do not know what "providername"
actually is. Below code answers the question:
Location location = new Location(LocationManager.GPS_PROVIDER);
location.setLatitude(23.5678);
location.setLongitude(34.456);
Here I am using LocationManager.GPS_PROVIDER
as the provider name.