Google Maps API 中的“元视口 user-scalable=no"有什么意义 [英] What's the point of 'meta viewport user-scalable=no' in the Google Maps API

查看:27
本文介绍了Google Maps API 中的“元视口 user-scalable=no"有什么意义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Google Maps JavaScript API V3 和 官方示例总是包含这个元标记:

I'm using the Google Maps JavaScript API V3 and the official examples always have you include this meta tag:

<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

我见过的大多数 3rd-party 示例也都这样做.不过,我用它写了一个插件,我的一个用户 告诉我这会阻止他在移动设备上放大和缩小.我没有可用于测试的移动设备,而且我的搜索均未显示任何有用的信息.

Most of the 3rd-party examples I've seen also do it. I wrote a plugin using it, though, and one of my users told me it's preventing him from being able to zoom in and out on his mobile device. I don't have a mobile device to test with, and none of my searches revealed any helpful information.

那么,标签的意义何在?我应该把它留在里面吗?我应该尝试检测浏览器代理并仅在桌面浏览器中显示它吗?

So, what's the point of the tag? Should I leave it in? Should I try to detect the browser agent and only show it for desktop browsers?

如果您想检查插件,可以下载浏览源查看实例.

If you want to examine the plugin, you can download it, browse the source or see a live example.

推荐答案

在许多设备(例如 iPhone)上,它会阻止用户使用浏览器的缩放功能.如果您有地图并且浏览器进行了缩放,那么用户将看到带有巨大像素化标签的大像素化图像.这个想法是用户应该使用谷歌地图提供的缩放.不确定与您的插件是否有任何交互,但这就是它的用途.

On many devices (such as the iPhone), it prevents the user from using the browser's zoom. If you have a map and the browser does the zooming, then the user will see a big ol' pixelated image with huge pixelated labels. The idea is that the user should use the zooming provided by Google Maps. Not sure about any interaction with your plugin, but that's what it's there for.

最近,正如@ehfeng 在他的回答中指出的那样,Android 版 Chrome(也许还有其他人)利用了这样一个事实,即没有原生浏览器可以在具有这样设置的视口标签的页面上进行缩放.这允许他们摆脱可怕的 300 毫秒触摸事件延迟,浏览器需要等待并查看您的单点触摸是否最终会成为双点触摸.(想想单击"和双击".)但是,当最初提出这个问题时(2011 年),在任何移动浏览器中都不是这样.这只是最近偶然出现的令人敬畏的东西.

More recently, as @ehfeng notes in his answer, Chrome for Android (and perhaps others) have taken advantage of the fact that there's no native browser zooming on pages with a viewport tag set like that. This allows them to get rid of the dreaded 300ms delay on touch events that the browser takes to wait and see if your single touch will end up being a double touch. (Think "single click" and "double click".) However, when this question was originally asked (in 2011), this wasn't true in any mobile browser. It's just added awesomeness that fortuitously arose more recently.

这篇关于Google Maps API 中的“元视口 user-scalable=no"有什么意义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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