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

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

问题描述

如何在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 ?

例如我使用这个代码在OSMDroid上实现MapBox: 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.

推荐答案

修改

官方Mapbox Android SDK发布。

Official Mapbox Android SDK is released.

另请参见Mapbox的答案。

Also, see Mapbox's answer.

对于downvote的人,我在sdk存在之前回答了问题。

To people who downvote, I answered the question before the sdk exists.

=============================================

=============================================

我认为 Nutiteq 看起来很有前途。他们的API有很多功能。此外,他们的演示项目也被内联评论。您可以查看此项目。特别是, 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.

希望这有帮助。

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

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