سؤال

I am trying to build an android app using leaflet which can work offline with tiles stored locally on the device's sd card. Is this possible and is there a recommended way to reference the local drive in the url? I have tried all combinations but it fails to load the tiles. I do have a similar app built using OSMdroid that works just fine retrieving the locally stored tiles. I am just trying to get the same working using leaflet.

Any suggestions or is this just not possible? Thanks!

My app activity's onCreate:

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebView= (WebView)findViewById(R.id.mapview);
        mWebView.setWebChromeClient(new WebChromeClient());
        mWebView.loadUrl("file:///android_asset/map.html");
    }

I have the map.html in assets folder along with leaflet.js. Below is a snippet of my map.html:(I think the issue is with the url - /sdcard/osmdroid/...)

<script>

    var map = L.map('map');

    L.tileLayer('/sdcard/osmdroid/', {
        attribution: 'Map data from MOBAC',
        maxZoom: 18
    }).addTo(map);
    map.locate({setView: true, maxZoom: 16});
    function onLocationFound(e) {
        var radius = e.accuracy / 2;

        L.marker(e.latlng).addTo(map)
        .bindPopup("You are within " + radius + " meters from this point").openPopup();

        L.circle(e.latlng, radius).addTo(map);
    }

</script>

هل كانت مفيدة؟

المحلول

Here is an example especially putMapsOnSd save it on sd https://github.com/tomkincaid/PathExample/blob/master/src/com/example/pathexample/MainActivity.java

and he read this file at onCreate

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top