0

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?

Allen
  • 29
  • 6
  • There is much talk of locations and CSV, but the only question I could find was how to display Toast. Displaying Toast has been covered many times already. If you had intended a different question, give some thought and time to carefully rewriting to make clear your specific question. Perhaps the this can be reopened. – Basil Bourque Jan 09 '20 at 17:43
  • @@Basil, it was not about displying toast message, which I know how to use toast. I tried to mean show the results in a toast message. Anyway, as per your suggestion, I edited my question to explain the purpose of my question – Allen Jan 10 '20 at 06:28
  • Duplicate: [*Calculating distance between two points, using latitude longitude?*](https://stackoverflow.com/q/3694380/642706) – Basil Bourque Jan 11 '20 at 08:47

0 Answers0