在Android项目中显示Tilemills mbtiles的代码

我正在开发一个Android项目,其中必须使用mbtiles显示离线地图.是否有任何教程显示如何在android项目中设置mbtiles.

解决方法:

很抱歉,您是先生.但是,看来www.google.com不是您最好的朋友…

无论如何,让我们建设性地:

1.)您可以使用MapBox SDK. Here是链接,其中是有关如何使用在线地图的示例.现在,对于离线地图并没有太大用处,但是您可以在其中找到SDK.只需下载它,即可在其中找到一个测试应用程序,在这里您可以了解这些家伙是如何做到的.

我相信必须有一种更简单的方法来安装库,但是我必须导入很多新内容才能使此工作正常进行.另外,请小心获取最新的库jar,因为我有okhttp-urlconnection-2.0.0.jar,并且在显示视图时应用程序崩溃了.然后我发现我需要版本2.1.0 jar.

2.)对于离线地图导入,我发现此link有用,因为它提供了一些代码,减轻了我无法正常显示地图的痛苦.
如果链接死代码状态:

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" />

如果您在xml this中需要mapbox id属性,那么问题将得到答案.

基本上,因为我只显示了地图,所以这很简单…
您需要在Assets文件夹中放置.mbtiles文件.
库无需显示任何错误;).
在xml文件中,放置了MapView自定义视图.

然后在您的活动中:

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

然后,您可以添加自定义设置,例如缩放和填充.

祝您离线地图万事如意.

上一篇:java-Mapbox无法在片段中工作


下一篇:Mapbox Studio绘制3D模型