Google Maps v3 - 在客户端上映射磁贴缓存?

时间:2011-11-16 12:55:17

标签: javascript google-maps caching google-maps-api-3

我正在使用Google Maps JS API v3进行项目。有没有办法让地图在客户端的机器上缓存切片,这样当他们刷新浏览器时,瓷砖不必再次全部下载?

我的许多客户都在蜂窝网络连接上,重新下载地图需要相当长的时间。

谢谢!

3 个答案:

答案 0 :(得分:11)

默认情况下,google maps会返回缓存的图片(您可以在控制台的网络标签中看到这一点)。

enter image description here

如果用户在缓存图像时遇到问题,可能是因为他们禁用了缓存

答案 1 :(得分:6)

这实际上可以使用HTML5及其缓存清单功能。我建议更新这个问题(和答案)。

Google编码员自己已经解决了这个问题,遗憾的是,这些信息并未得到很好的传播。

必读读物

  1. 首先在这里查看Google Code博文:http://googlecode.blogspot.com/2010/04/google-apis-html5-new-era-of-mobile.html
  2. 然后阅读密苏里州立大学自己的帖子:http://blogs.missouristate.edu/web/2010/05/12/google-maps-api-v3-developing-for-mobile-devices/
  3. 技术

    • 必须缓存Google地图使用的每个网址
    • 通过从“离线网站”中删除Chrome和Firefox的顽固缓存方法,采用方法
    • 所有自定义项必须是javascript中的客户端

    你的缓存文件看起来像(根据密苏里州):

    CACHE MANIFEST
    /map/mobile/examples/template.aspx
    /map/mobile/examples/template.css
    /map/mobile/examples/template.js
    NETWORK:
    http://maps.gstatic.com/
    http://maps.google.com/
    http://maps.googleapis.com/
    http://mt0.googleapis.com/
    http://mt1.googleapis.com/
    http://mt2.googleapis.com/
    http://mt3.googleapis.com/
    http://khm0.googleapis.com/
    http://khm1.googleapis.com/
    http://cbk0.googleapis.com/
    http://cbk1.googleapis.com/
    http://www.google-analytics.com/
    http://gg.google.com/
    

    注意事项

    您需要完全基于HTML5,并认识到这将对您的用户产生的影响。这种情况非常方便,您的用户可以使用最新的浏览器标准/设备,也可以控制用户选择。

    希望这有帮助。

答案 2 :(得分:5)

之前的答案是缓存清单功能不正确。如果您在http://www.w3.org/TR/html5/offline.html阅读规范,在“5.7.3缓存清单语法”下,您将看到清单文件的NETWORK部分实际列出了不应缓存的资源:

# here is a file for the online whitelist -- it isn't cached, and
# references to this file will bypass the cache, always hitting the
# network (or trying to, if the user is offline).
NETWORK:
comm.cgi

上一张海报的例子实际上是在说:

1)缓存以下文件:

/map/mobile/examples/template.aspx
/map/mobile/examples/template.css
/map/mobile/examples/template.js

2)从网络中获取以下内容:

http://maps.gstatic.com/
http://maps.google.com/
http://maps.googleapis.com/
http://mt0.googleapis.com/
http://mt1.googleapis.com/
http://mt2.googleapis.com/
http://mt3.googleapis.com/
http://khm0.googleapis.com/
http://khm1.googleapis.com/
http://cbk0.googleapis.com/
http://cbk1.googleapis.com/
http://www.google-analytics.com/
http://gg.google.com/
相关问题