-1

I'm working on a project where in I have to parse the CSV file from an URL that has latitudes and longitudes and display it on a Map. The link for the data is here. The data here updates every 5 mins and hence there is no point of saving it and reading the file. So I want to read it dynamically and show it on the map, as the data updates, everything gets updated.

I have done little work here, but I'm not getting the expected result. Instead it is showing some stack of error messages.

The error message

My code is below.

    BufferedReader buffer = null;
    String line;
    ArrayList<String> latitudes = new ArrayList<>();
    ArrayList<String> longitudes = new ArrayList<>();
    ArrayList<String> places = new ArrayList<>();
    ArrayList<LatLng> latsLons = new ArrayList<LatLng>();

    try {
        URL url = new URL("https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.csv");
        URLConnection connection = url.openConnection();
        InputStream input = connection.getInputStream();

        buffer = new BufferedReader(new InputStreamReader(input));
        while((line = buffer.readLine()) != null) {
            String[] room = line.split(",");
            latitudes.add(room[1]);
            longitudes.add(room[2]);
            places.add(room[13]);
        }
        latitudes.remove(0); // remove heading
        longitudes.remove(0);
        places.remove(0);
        for (int i = 0; i < latitudes.size(); i++) {
            latsLons.add(new LatLng(Double.parseDouble(latitudes.get(i)),
                    Double.parseDouble(longitudes.get(i))));
        }

    } catch (NullPointerException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (buffer != null) {
            try {
                buffer.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    for (LatLng pos: latsLons) {
        mMap.addMarker(new MarkerOptions().position(pos).title("Earthquake place"));
    }

Can somebody help me fix this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115

1 Answers1

0

you can use google's firebase real-time database service.Its sync data with your app real-time.

Eranga Gamagedara
  • 536
  • 1
  • 3
  • 10