How to connect DB SQLite with Mapsforge in Android?

211 views
Skip to first unread message

Aloisius Gonzaga

unread,
Mar 20, 2017, 12:54:00 AM3/20/17
to mapsforge-dev
Hello... i am newbie in android dev and i want to bulid a maps app with openstreetmap data. 

I used mapsforge libs to connect my app with the maps. Now, i want to connect my app with DB SQLite but i don't know what should i do..
is there any tutorial that can help me to solve my problem? 

Thanks :D Sorry if my english is not good....

Emux

unread,
Mar 20, 2017, 3:25:19 AM3/20/17
to mapsfo...@googlegroups.com
If you want to use the Mapsforge POIs for offline search you can check the relevant guide.

And there is the PoiSearchViewer example in mapsforge-samples-android samples, which demonstrates the POI search.

--
Emux

Aloisius Gonzaga

unread,
Mar 31, 2017, 12:08:22 AM3/31/17
to mapsforge-dev
thanks Emux,  for your explain ... and i'm sorry for the late response ...

but i still confused. Is it same with SQLite ...? Because, I recently heard it ...
Can you tell me what is POI?

Thanks ...: D

Emux

unread,
Mar 31, 2017, 2:09:09 AM3/31/17
to mapsfo...@googlegroups.com
Can you explain more what exactly you want to do with SQLite?

SQLite can be a database in Android device, do you want to read map tiles from it, to read points of interest, or something else?

--
Emux

Aloisius Gonzaga

unread,
Mar 31, 2017, 11:47:44 PM3/31/17
to mapsforge-dev
I plan to create an android map app based on android for firefighters.

I'm using mapsforge as the map viewer in android. I plan to use the SQLite database to save information like traffic jam data and hydrant locations.
I will try to combine those data with spesific artificial intelligence algorithms (like Djikstra or something else) for routing.

Maybe you have
a better suggestion for me .. Thanks ...

Emux

unread,
Apr 1, 2017, 4:39:43 AM4/1/17
to mapsfo...@googlegroups.com
You can use Mapsforge for map view and overlay geometries on top of map (like demonstrated in OverlayMapViewer).

And if you want to create your own maps with custom data, have a look at map-writer documentation.

Mapsforge POI like described in its documentation is about storing "points of interest" in an DB and perform queries for fast search on them.

Regarding routing you can have also a look at GraphHopper an open source routing library.
It has Android examples using VTM here or Mapsforge here.

--
Emux

LoisZaga

unread,
Apr 1, 2017, 9:24:35 AM4/1/17
to mapsforge-dev
Oke Emux... thanks for your advice.. i will learn about that...

By the way, i need some help.. can you help me?
I learn and try some code from getting_started_mapsforge, it use "Activity"
Now i want to display the map use "Fragment" but when i run the code, it still give me error message "Unfortunately app has stopped"..


public class HomeFragment extends Fragment {

// name of the map file in the external storage
private static final String MAP_FILE = "berlin.map";

public MapView mapView;

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

View v = inflater.inflate(R.layout.home,null);

AndroidGraphicFactory.createInstance(getActivity().getApplication());

mapView.setClickable(true);
mapView.getMapScaleBar().setVisible(true);
mapView.setBuiltInZoomControls(true);
mapView.setZoomLevelMin((byte) 10);
mapView.setZoomLevelMax((byte) 20);

// create a tile cache of suitable size
TileCache tileCache = AndroidUtil.createTileCache(getActivity(), "mapcache",
mapView.getModel().displayModel.getTileSize(), 1f,
this.mapView.getModel().frameBufferModel.getOverdrawFactor());

// tile renderer layer using internal render theme
MapDataStore mapDataStore = new MapFile(new File(Environment.getExternalStorageDirectory(), MAP_FILE));
TileRendererLayer tileRendererLayer = new TileRendererLayer(tileCache, mapDataStore,
this.mapView.getModel().mapViewPosition, AndroidGraphicFactory.INSTANCE);
tileRendererLayer.setXmlRenderTheme(InternalRenderTheme.DEFAULT);

// only once a layer is associated with a mapView the rendering starts
this.mapView.getLayerManager().getLayers().add(tileRendererLayer);

this.mapView.setCenter(new LatLong(52.517037, 13.38886));
this.mapView.setZoomLevel((byte) 12);

return v;
}

@Override
public void onDestroy() {
this.mapView.destroyAll();
AndroidGraphicFactory.clearResourceMemoryCache();
super.onDestroy();
}
}








Emux

unread,
Apr 1, 2017, 9:34:17 AM4/1/17
to mapsfo...@googlegroups.com
You can have a look at mapsforge-samples-android which has a fragment example with Mapsforge maps.

--
Emux
Reply all
Reply to author
Forward
Message has been deleted
0 new messages