如何使用MapBox在Android [英] How can i use MapBox on Android

查看:319
本文介绍了如何使用MapBox在Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示在Android MapBox瓷砖?我尝试使用它OSMDroid,并Nutiteq没有成功。是否有MapBox的是Android库?

How can i display MapBox tiles on Android ? I tried using it with OSMDroid, and Nutiteq with no success. Is there a android library for MapBox ?

例如我用这个code实现MapBox的OSMDroid:<一href="http://blog.spatialnetworks.com/post/2012/07/using-mbtiles-on-android-with-osmdroid">http://blog.spatialnetworks.com/post/2012/07/using-mbtiles-on-android-with-osmdroid

For example i used this code to implement MapBox on OSMDroid : http://blog.spatialnetworks.com/post/2012/07/using-mbtiles-on-android-with-osmdroid

XYTileSource MBTILESRENDER = new XYTileSource("mbtiles", ResourceProxy.string.offline_mode, 1, 20, 256, ".png", "http://example.org/");
DefaultResourceProxyImpl mResourceProxy = new DefaultResourceProxyImpl(this.getApplicationContext());
SimpleRegisterReceiver simpleReceiver = new SimpleRegisterReceiver(this.getActivity());

File f = new File(Environment.getExternalStorageDirectory(), "mymbtilesfile.mbtiles");

IArchiveFile[] files = { MBTilesFileArchive.getDatabaseFileArchive(f) };

MapTileModuleProviderBase moduleProvider = new MapTileFileArchiveProvider(simpleReceiver, MBTILESRENDER, files);

MapTileProviderArray mProvider = new MapTileProviderArray(MBTILESRENDER, null, new     MapTileModuleProviderBase[] { moduleProvider });

this.mMapView = new MapView(this, 256, mResourceProxy, mProvider);

但它没有工作,我想直接从网页加载MbTiles。

But it didn't work, i want to load MbTiles directly from the web.

推荐答案

我觉得 Nutiteq 看起来pretty的前途。他们的API有很多的功能。此外,他们的演示项目在线评论。您可以检查出这个项目。尤其是,<一个href="https://github.com/nutiteq/hellomap3d/blob/master/AdvancedMap3D/src/main/java/com/nutiteq/advancedmap/MBTilesMapActivity.java">MBTilesMapActivity可能是东西,你要寻找的。该类展示了如何使用mbtiles工作:

I think Nutiteq looks pretty promising. Their API has a lot of features. Also, their demo projects are inline commented. You can check out this project. Especially, MBTilesMapActivity might be something that you're looking for. The class shows how to work with mbtiles:

// 1. Get the MapView from the Layout xml
mapView = (MapView) findViewById(R.id.mapView);
// 2. create and set MapView components
Components components = new Components();
mapView.setComponents(components);
// 3. Define map layer for basemap
MBTilesMapLayer dbLayer = new MBTilesMapLayer(new EPSG3857(), 0, 19, file.hashCode(), file, this);
mapView.getLayers().setBaseLayer(dbLayer);
...
// 4. Start the map - mandatory
mapView.startMapping();        
// 5. zoom buttons using Android widgets - optional
// get the zoomcontrols that was defined in main.xml
ZoomControls zoomControls = (ZoomControls) findViewById(R.id.zoomcontrols);


您还可以看看这是从他们的演示修改我的玩具项目。基本上,我的应用程序允许用户输入一个mbtiles文件的URL。然后,它会下载该文件并加载它的MapView。


You can also take a look at my toy project which is modified from their demo. Basically, my app allows the user to input a url of a mbtiles file. Then, it downloads the file and loads it to the MapView.

如果你真的要坚持OSMDroid,可能有帮助。我还没有机会尝试,但。

If you really have to stick with OSMDroid, this might be helpful. I haven't had a chance to try it though.

希望这有助于。

这篇关于如何使用MapBox在Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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