Code to Display the Tilemills mbtiles in android project

大兔子大兔子 提交于 2019-12-01 12:20:21
zed

sorry for being mr.Obvious, but it seems that www.google.com isn't your best friend...

Anyways, lets be constructive:

1.) You can use the MapBox SDK. Here is the link where is an example on how to use the online map. Now, that isn't of much use for the offline maps, but in there you can find the SDK. Just download it, and in there you can find also a test app where you can find out how the guys did it.

I beleive there must be an easier way to install the library, but I had to import lots of new stuff to make this work. Also, be careful to get latest library jar's since I had okhttp-urlconnection-2.0.0.jar and the app crashed upon showing the view. And then I found out that I needed version 2.1.0 jar.

2.) For offline map import I found this link helpful as it offers bits of code that eased my suffering to show the map properly. In case the link dies code states:

To start create, for example, a method called setupMaboxOffline() in your WearActivity:

public void setupMaboxOffline() {
    MapView mapView = (MapView) findViewById(R.id.mapview);
    mapView.setZoom(5);
    mapView.setCenter(new LatLng(38.8977, -77.0365));
    mapView.setTileSource(new MBTilesLayer(this, "control-room-0.2.0.mbtiles"));
}

Then, call it within the WatchViewStub in onCreate(). This stub is used by Android Wear to choose the right layout (round or square) depending on the shape of the watch the user has.

The MapView referenced above looks like this (in both layouts):

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

In case you'd need mapbox id property in the xml this SO question gets the answer.

Basically, as I've only displayed the map, this is fairly simple... You need your .mbtiles file inside assets folder. Library needs to be showing no errors ;). In your xml file you've put the MapView custom view.

Then in your Activity:

MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setTileSource(new MBTilesLayer(this, "map.mbtiles"));

You can then add your custom settings like zoom and stuff.

Good luck with your offline map. :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!