nathanhollows / NuggetNav

A compass that points to the nearest ready to eat chicken nuggets
https://nuggetwatch.co.nz
1 stars 0 forks source link

Store geojson locally #7

Closed nathanhollows closed 5 years ago

nathanhollows commented 5 years ago

To ensure the app is usable straight away without a wifi connection the location data should be stored locally and then cached in future. The location data is from nuggetwatch.co.nz/locations

Here's how it should work:

nathanhollows commented 5 years ago

These lines in MapActivity set fetch the locations. MapBox automatically fetches it using the URI, but it would also accept a string instead. The okhttp library might be a simple way to fetch and cache this.

// Add a new source from the GeoJSON data and set the 'cluster' option to true.
try {
    source = new GeoJsonSource("locations",
            new URI("https://nuggetwatch.co.nz/locations"), // this line here
            new GeoJsonOptions()
                    .withCluster(true)
                    .withClusterMaxZoom(14)
                    .withClusterRadius(50)
    );
    loadedMapStyle.addSource(source);
} catch (URISyntaxException uriSyntaxException) {
}

MapBox docs for GeoJsonSource

nathanhollows commented 5 years ago

ee9f0cd stores the locations file in a cache for 24 hours. I'm not sure if it holds it indefinitely if the phone isn't internet connected. In case the connection fails it should still pull from a local copy if there is nothing else available

nathanhollows commented 5 years ago

There's a race condition when loading the locations json file and building the map. The app occasionally loads the file first and tries to add it to the map before it is fully initialised. It can cause a crash on start up

nathanhollows commented 5 years ago

Solved with 724b01311b52dcda68084108586723d72639eaee