Using Location Manager, I get user device location (latitude and longitude) on a button click. I have also coordinates stored in a CSV file (data.csv), which I put it in a Assets folder. To distinguish the two, I use Lat_u, Long_u
for user device location, and Lat_c, Long_c
for coordinate in the CSV file. The data.CSV doesn't need updates and can be exported with the App. My intention is to compare user device location with the location coordinates in the CSV. When user approaches to any of the location in the csv file, the program returns true
and posts its placeName
. The format of the CSV file is as follows:
lat_c, long_c, placeName
37.004934,-122.783378, place1
37.004891,-122.786897, place2
37.005580,-122.786575, place3
37.003970,-122.787734, place4
onClickListner, I have the following:
LocationManager lm = (LocationManager) getContext().getSystemService(Context.LOCATION_SERVICE);
LocationListener ll = new myLocationlistner();
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
And on location update, I have the following:
public void onLocationChanged(Location location) {
if (location !=null)
{
String lat_u=String.format("%.6f",location.getLatitude());
String long_u=String.format("%.6f",location.getLongitude());
}
}
New to Android and java, can anyone give me an example on how to compare user device location with the coordinates in the csv file, then return true or false depending on how close the user's device. If true, include the placeName the user's device is closer to?