Search code examples
javaandroidopenstreetmaposmdroid

Why osmdroid not working in offline mode (multiple questions)?


I am working on the OSMdroid library, and wanted to make it offline so i used this code

 mMapView.setUseDataConnection(false);

but in this condition it won't even display the map other than the graph page. But when i change the boolean to true it again starts working.

So how do i make it work completely offline?

I am also trying to get the poi so i have the following code

 geoPoint= new GeoPoint(37.439974,-119.003906);
 double north = 84;
    double east = -180;
    double south = -84;
    double west = 180;
    boundingBoxE6 = new BoundingBoxE6(north, east, south, west);
    mMapView.setScrollableAreaLimit(boundingBoxE6);
    mMapView.setMultiTouchControls(true);
    Marker marker= new Marker(mMapView,mResourceProxy);
    marker.setPosition(geoPoint);
    mMapView.getOverlays().add(marker);
    poiMarkers = new FolderOverlay(getActivity());
    new connection().execute();
    mMapView.invalidate();


public class connection extends AsyncTask{

    @Override
    protected Object doInBackground(Object[] objects) {
        NominatimPOIProvider poiProvider = new NominatimPOIProvider();
        pois=poiProvider.getPOICloseTo(geoPoint,"atm",50,1000);
        return pois;
    }

    @Override
    protected void onPostExecute(Object o) {
        super.onPostExecute(o);
        mMapView.getOverlays().add(poiMarkers);
        Drawable poiIcon = getResources().getDrawable(R.drawable.marker_poi_default);
        if (o != null) {
            for (POI poi : pois) {
                Marker poiMarker = new Marker(mMapView);
                poiMarker.setTitle(poi.mType);
                poiMarker.setSnippet(poi.mDescription);
                poiMarker.setPosition(poi.mLocation);
                poiMarker.setIcon(poiIcon);
                poiMarkers.add(poiMarker);
            }
        }else{
            Toast.makeText(getActivity(),"null",Toast.LENGTH_SHORT).show();
        }
    }
}

But instead of getting the poi on the given geopint i get it somewhere else and everytime i mean whatever the code i change i don't get the poi in any other places other than that

http://nominatim.openstreetmap.org/search?format=json&q=[atm]&limit=50&bounded=1&viewbox=-1119.003906,1037.439974,880.996094,-962.560026

Is it possible to access poi in offline mode?


Solution

  • As for the offline tiles showing, are you sure you have the offline map tiles .ZIP-file stored in /mnt/sdcard/osmdroid/ (or whatever the path for your device's SDcard is, it just has to be within this folder in a subdirectory called osmdroid)?

    A good tutorial that helped me can be found here: http://www.haakseth.com/?p=30

    The OSMdroid TileSource will automatically look for this .ZIP-file if there is no internet connection to retrieve the tiles from. In the OpenStreetMapTileProviderConstants class there is this piece of code:

    /** Base path for osmdroid files. Zip files are in this folder. */
    public static final File OSMDROID_PATH = new File(Environment.getExternalStorageDirectory(),
            "osmdroid");
    

    So as you can see, you just need to have the osmdroid-directory in your SDcard folder, and everything should work just fine.

    If you don't have a map tiles .ZIP yet, check out Mobile Atlas Creator for creating this.