浏览器H5定位即navigator.geolocation,通过IP或者域名的形式,如:http://172.21.3.82:8080 和http://b.cunzhang.com进行访问时,调用navigator.geolocation.getCurrentPosition,打开控制台,你会发现有以下错误信息:
Only secure origins are allowed (see: https://goo.gl/Y0ZkNV).
“只有在安全来源的情况才才被允许”。错误信息里还包含了一个提示链接,我们不妨打开这个
链接https://goo.gl/Y0ZkNV)看看。原来,为了保障用户的安全,Chrome浏览器认为只有安全的
来源才能开启定位服务。那什么样才算是安全的来源呢?在打开链接的页面上有这么一段话:
“Secure origins” are origins that match at least one of the following (scheme, host, port) patterns:(https, *, *)
(wss, *, *)
(*, localhost, *)
(*, 127/8, *)
(*, ::1/128, *)
(file, *, —)
(chrome-extension, *, —)
This list may be incomplete, and may need to be changed. Please discuss!
大概意思是说只有包含上述列表中的scheme、host或者port才会被认为是安全的来源,现在这个列表还不够完整,后续可能还会有变动,有待讨论。
如果需要在域名访问的基础上实