android - 我如何在 Android 上使用 MapBox

标签 android map mapbox

<分区>

如何在 Android 上显示 MapBox 瓦片?我尝试将它与 OSMDroid 和 Nutiteq 一起使用,但没有成功。是否有 MapBox 的 android 库?

例如,我使用此代码在 OSMDroid 上实现 MapBox: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。

最佳答案

编辑

Official Mapbox Android SDK is released.

Also, see Mapbox's answer.

对于投反对票的人,我在 sdk 存在之前就回答了这个问题。

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

我认为Nutiteq看起来很有前途。他们的 API 有很多功能。此外,他们的演示项目是内联评论的。你可以看看this project .特别是,MBTilesMapActivity可能是您正在寻找的东西。该类(class)展示了如何使用 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);

你也可以看看my toy project这是从他们的演示中修改的。基本上,我的应用程序允许用户输入 mbtiles 文件的 url。然后,它下载文件并将其加载到 MapView。

如果你真的必须坚持使用 OSMDroid,this可能会有帮助。不过我还没有机会尝试。

希望这对您有所帮助。

关于android - 我如何在 Android 上使用 MapBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17028496/

相关文章:

android - 如何在 Windows 7 中取消签名 bcprov-jdk15on-146.jar?

android - 根据手机当前方向旋转 Mapbox map

ios - 如何在 IBAction 按钮中初始化 Tile 源一次

grails - 如何间接引用 grails GSP 模型变量,例如通过 .get(...)

c++ - map 的 union 迭代器?

javascript - 为什么 Mapbox everyLayer 函数不会在每次加载页面时触发?

android - 如何控制进度条的出现/消失,就像在android fragment 中加载一样?

android - 如何在 android 文件上设置扩展用户属性?

java - TCP 套接字 IOException 绑定(bind)失败 : EADDRINUSE (Address already in use)

c++ - 如何从一个 map 键列表中减去另一个 map 键列表并获得新 map ( map A - mab B = map C)