Pratik Bhat
Pratik Bhat

Reputation: 7614

How can I implement an offline geocoder for a single city using OSM data in android?

I am trying to develop an offline android map that makes use of OSM map tiles of a particular zoom level, For this purpose I used an open source library : Osmdroid

Now, I am looking into the possibility of creating an offline geocoding/ reverse geocoding for a single city that can be integrated with my application,

can I use Osm xml data for that purpose? if so , then can anyone suggest/explain how to use it to create SQlite db.. to be used with my app

I read here and also here about Spatialite
But cannot quite understand its working and implementation

Thanks

Upvotes: 18

Views: 4305

Answers (2)

Miguel Tomás
Miguel Tomás

Reputation: 1911

This has an answer in here https://stackoverflow.com/a/64811929/13794189

and goes as follows:

To use Open Street Maps (OSM) in offline mode you need to first implement a download manager like the one shown here on the post liked bellow. It has resume capabilities which is good for very large files :

https://stackoverflow.com/a/64811752/13794189

next you can load the downloaded OSM maps file in to a mapView like this:

     org.osmdroid.config.IConfigurationProvider osmConf = org.osmdroid.config.Configuration.getInstance();
    File basePath = new File(SessionData.offlineMapsDirectoryPath, "osmdroid");
    osmConf.setOsmdroidBasePath(basePath);
    File tileCache = new File(SessionData.offlineMapsDirectoryPath, "tile");
    osmConf.setOsmdroidTileCache(tileCache);

    map = (MapView) getActivity().findViewById(R.id.map);  // create basic map
    //map.setTileSource(TileSourceFactory.DEFAULT_TILE_SOURCE);
    map.setTilesScaledToDpi(true);
    map.setMultiTouchControls(true);
    map.setUseDataConnection(false);

    // add compass to map
    //CompassOverlay compassOverlay = new CompassOverlay(getActivity(), new InternalCompassOrientationProvider(getActivity()), map);
    //compassOverlay.enableCompass();
    //map.getOverlays().add(compassOverlay);

    //attach listeners
    MapEventsOverlay mapEventsOverlay = new MapEventsOverlay(this);
    map.getOverlays().add(0, mapEventsOverlay);

In the code above, SessionData.offlineMapsDirectoryPath is the path where the downloaded file is saved.

Don't forget to add in your gradle file the following implementations:

implementation 'org.osmdroid:osmdroid-android:6.1.0'
implementation 'com.github.MKergall:osmbonuspack:6.6.0'

Upvotes: 0

Alexander Roehnisch
Alexander Roehnisch

Reputation: 715

With the Skobbler SDK you have offline maps and (reverse) geocoding.

Upvotes: 1

Related Questions