问题描述
如何显示在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: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有很多的功能。此外,他们的演示项目在线评论。您可以检查出这个项目。尤其是,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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!