Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Location object in Android with latitude and longitude values

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 coordinates, and my current location.

The Location class has a simple method to find the distance between two Location objects, so I figured I'd make a Location object with the coordinates, then call the method.

Is there an easy way to do this? Also, if there's another reliable, fairly simple equation that won't clutter things too much, that would work too. Thanks.

(android.location.Location)

like image 740
fonduman Avatar asked Aug 01 '13 01:08

fonduman


People also ask

How do I set latitude and longitude on Android?

Select Location > Then set the Latitude and Longitude values. Then press Send to set the Latitude and Longitude values to the emulator device.

Which mobile app is used to determining latitude and longitude of a place?

For Android users, Google Maps is the simplest way to either enter latitude and longitude coordinates or to find out your current coordinates. If you want to find your current coordinates, zoom into your location and hold down on the touchpad screen in the map.


1 Answers

Assuming that you already have a location object with your 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); 
like image 199
Androiderson Avatar answered Sep 27 '22 21:09

Androiderson