使用MapBox的Andr​​oid SDK离线瓷砖缓存 [英] Offline tile caching using MapBox Android SDK

查看:1508
本文介绍了使用MapBox的Andr​​oid SDK离线瓷砖缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个工作原型的iOS使用iOS的拼贴缓存技术,如下图所示(Objective-C的code):

I have a working iOS prototype using the iOS tile-caching technique as shown below (Objective-C code):

RMTileCache  * tileCache = [[RMTileCache alloc] initWithExpiryPeriod:0]; 
[tileCache setBackgroundCacheDelegate:self]; 
RMMapboxSource * tileSource = [[RMMapboxSource alloc] initWithMapID:mapID]; 
[tileCache beginBackgroundCacheForTileSource:tileSource southWest:southWest northEast:northEasth minZoom:minZoom maxZoom:maxZoom];

这是什么做主要是下载地图,永久缓存砖和有可能使应用程序在未来脱机运行。由于我们将通过官方祈祷,API,这当然是不违反任何的法律限制。

What this basically does is download the map, cache the tiles permanently and make it possible for the app to run offline in the future. Since we're going through the official payed API, this is of course not violating any of the legal restrictions.

现在我想实现在Android上是相同的。我在Android的Studio中运行SDK和一个远程地图使用地图ID,基本上这(Android的Eclipse的布局XML)的一个工作项目:

Now I'd like to achieve the same on Android. I have the SDK running in Android Studio and a working project with a remote map using the Map ID, basically this (Android Eclipse layout XML):

<com.mapbox.mapboxsdk.views.MapView
    android:id="@+id/mapview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    mapid="my_map_id" />

这工作得很好,但解决的办法了一次缓存是完全脱机的人。我的问题是:有没有相当于Java的iOS的来源$ C ​​$ C以上的MapBox SDK?我试图寻找在API中,也没有找到一个可靠的参考,以瓷砖缓存系统。经过一番痛苦的时候试图让它运行的基础上的方法名称和code文档,我放弃了。

This works fine, but the solution has to be completely offline once the caching is done. My question is: is there a Java equivalent of the iOS source code above in the MapBox SDK? I attempted to look in the API, but could not find a solid reference to the tile caching system. And after some painful time trying to get it running based on the method names and code documentation, I gave up.

我跑MapBox的最新GitHub的分布以及最新的Andr​​oid工作室,一切都正常运行正常,但找不到code做到这一点。我不一定需要API参考,code的几行展示它是如何做就足够了。

I'm running the latest GitHub distribution of MapBox along with the latest Android Studio, everything's up and running fine, but can't find the code to accomplish this. I don’t necessarily need an API reference, a few lines of code showing how it’s done would be enough.

推荐答案

离线瓷砖缓存支持现在的Mapbox的Andr​​oid SDK可作为0.5.1版本。发布了它20月 - 2014年。下面是如何开始一个基本的例子:

Offline Tile Caching support is now available in the Mapbox Android SDK as of version 0.5.1. It was released on 20-December-2014. Here's a basic example of how to get started:

OfflineMapDownloader offlineMapDownloader = OfflineMapDownloader.getOfflineMapDownloader(getActivity());
BoundingBox boundingBox = mapView.getBoundingBox();
CoordinateSpan span = new CoordinateSpan(boundingBox.getLatitudeSpan(), boundingBox.getLongitudeSpan());
CoordinateRegion coordinateRegion = new CoordinateRegion(mapView.getCenter(), span);
offlineMapDownloader.beginDownloadingMapID("MapboxMapID", coordinateRegion, (int) mapView.getZoomLevel(), (int) mapView.getZoomLevel());

要加载previously保存图:

To load a previously saved map:

ArrayList<OfflineMapDatabase> offlineMapDatabases = offlineMapDownloader.getMutableOfflineMapDatabases();
OfflineMapDatabase db = offlineMapDatabases.get(0);
OfflineMapTileProvider tp = new OfflineMapTileProvider(getActivity(), db);
offlineMapOverlay = new TilesOverlay(tp);
mapView.addOverlay(offlineMapOverlay);

这篇关于使用MapBox的Andr​​oid SDK离线瓷砖缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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