使用Phonegap离线浏览预先知道的地图 [英] Navigate through a pre-known map offline using Phonegap

查看:210
本文介绍了使用Phonegap离线浏览预先知道的地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,并提前感谢您,

我想询问是否有一种方法来编译预先知道的google地图图块,并加载到Phonegap应用程序。

I would like to ask if there is a way to compile pre-known google map tiles and load them up in a Phonegap application.

更具体地说,我正在开发一个关于地理位置,路径导航等在特定区域内的应用程序。由于应用程序的使用的性质(例如它可能用于野生动物),用户的电话可能不会得到信号以具有互联网连接,因此我想要交互式地图设施是可用的,即使手机已离线。

To be more specific, I am developing an application that will concern geolocation, path navigation etc, within a specific region. Due to the nature of use of the application (it might be used in the wildlife for example) the phone of the user may not get signal in order to have an internet connection, hence I want the interactive map facility to be available even if the phone is offline.

Im也考虑如果较早检索google地图,可以获取缓存磁贴。这是否可能与Phonegap?

Im also considering the possibility of getting the cached tiles if the google map was retrieved earlier. Is this possible with Phonegap?

我也打开其他地图服务,不只是在谷歌地图上的任何建议。

I am also open to any suggestions on other map services, not only on google maps.

推荐答案

我一直在使用OpenLayers通过phonegap来缓存Open Street Map tiles。我使用PhoneGap-Downloader(https://github.com/phonegap/phonegap-plugins/tree/master/Android/Downloader)将磁贴存储在文件系统上,并使用localstorage将磁贴的URL映射到文件系统上的位置。在openlayers中,我将子类化为OpenLayers.Layer.OSM以重载getURLasync并拦截图块URL的设置:

I've been working on caching Open Street Map tiles with phonegap using OpenLayers. I store the tiles on the filesystem using PhoneGap-Downloader (https://github.com/phonegap/phonegap-plugins/tree/master/Android/Downloader) and map the url of the tile to the location on the filesystem using localstorage. In openlayers I subclass OpenLayers.Layer.OSM to overload getURLasync and intercept the setting of the tile URL:

编辑:在最近版本的phonegap没有必要使用PhoneGap-Downloader插件,只需使用本地文件传输: http://docs.phonegap.com/en/2.3.0/cordova_file_file.md.html#FileTransfer_download

EDIT: In recent versions of phonegap there is no need for the PhoneGap-Downloader plugin, just use the native filetransfer: http://docs.phonegap.com/en/2.3.0/cordova_file_file.md.html#FileTransfer_download

OSMWithLocalStorage = OpenLayers.Class(OpenLayers.Layer.OSM, {
    initialize: function(options) {
        OpenLayers.Layer.OSM.prototype.initialize.apply(this, ["CachedMap"]);
        this.async = true;
        this.isBaseLayer = true;

        this.url = 'http://tile.openstreetmap.org/${z}/${x}/${y}.png';
    },
    getURLasync: function(bounds, scope, prop, callback) {
        var url = OpenLayers.Layer.OSM.prototype.getURL.apply(this, [bounds]);
        var cached = window.localStorage.get(url);

        if(cached){
            scope[prop] = cached;
        }
        else{
            scope[prop] = url;
        }

        callback.apply(scope);
    },
});

这篇关于使用Phonegap离线浏览预先知道的地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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