code钮显示Tilemills mbtiles在Android项目 [英] Code to Display the Tilemills mbtiles in android project

查看:391
本文介绍了code钮显示Tilemills mbtiles在Android项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个机器人项目中,我必须使用mbtiles显示离线地图。是否有任何教程展示了如何设置mbtiles inandroid项目。

解决方案

遗憾的是mr.Obvious,但似乎www.google.com是不是你最好的朋友......

不管怎么说,让有建设性的:

1)你可以使用MapBox SDK。 这里就是是一个例子链接如何使用在线地图。现在,这是多大用处的离线地图不大,但在那里你可以找到的SDK。只要下载它,并在那里你还可以找到一个测试应用程序,你可以找到的人是如何做的。

我beleive必须有安装库中的一个更简单的方法,但我不得不进口大量的新的东西,使这项工作。同时,应注意以获得最新的库JAR的,因为我有okhttp-的URLConnection-2.0.0.jar和应用程序崩溃时显示的视图。然后我发现我所需要的版本2.1.0罐子。

2)。对于离线地图的进口,我发现这个的 有用的链接,因为它提供了code,它减轻了我的痛苦正确显示的地图位。 在情况下,链接去世code状态:

  

要开始创建,例如,一个方法叫做setupMaboxOffline()在你的WearActivity:

 公共无效setupMaboxOffline(){
    图形页面图形页面=(图形页面)findViewById(R.id.mapview);
    mapView.setZoom(5);
    mapView.setCenter(新经纬度(38.8977,-77.0365));
    mapView.setTileSource(新MBTilesL​​ayer(这一点,控制室-0.2.0.mbtiles));
}
 

  

然后,WatchViewStub中的onCreate()中调用它。该存根用于Android Wear选择合适的布局(圆形或方形),这取决于用户的手表的形状。

     

以上引用的图形页面看起来像这样(在这两个布局):

 < com.mapbox.mapboxsdk.views.MapView
    机器人:ID =@ + ID /图形页面
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT/>
 

在情况下,你需要mapbox id属性的XML <一href="http://stackoverflow.com/questions/25986242/error-parsing-xml-unbound-$p$pfix-for-mapbox">this SO问题得到了答案。

基本上,我只显示在地图上,这是相当简单的... 你需要你的.mbtiles文件中的资产的文件夹。 库需要表示没有错误)。 在XML文件中,你已经把图形页面自定义视图。

然后在您的活动:

 图形页面图形页面=(图形页面)findViewById(R.id.mapview);
mapView.setTileSource(新MBTilesL​​ayer(这一点,map.mbtiles));
 

您可以然后像变焦之类的东西添加自定义设置。

祝你的离线地图。 :)

I am working on an android project in which i have to show the offline map using mbtiles . Is there any tutorial which shows how to set the mbtiles inandroid project .

解决方案

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. :)

这篇关于code钮显示Tilemills mbtiles在Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆