Leaflet.js - 在某些浏览器上无法获取我的当前位置

Leaflet.js - can't get my current location on some browsers

我制作了这个 application using Leaflet.js with these plugins: MarkerCluster, Leaflet Map Fullscreen,它托管在 Linux 服务器 HTTP apache2 中。

出于某种原因,我无法在以下浏览器上获取当前位置:

在 IE 中,它给了我一个允许定位我自己的弹出窗口,而且它有效……只有一次。如果我再次尝试定位自己,它的行为与上面的其他浏览器一样。

而且,如果我在 Instagram dm 中打开 link,它就可以正常工作...

它也适用于本地主机,或者如果我使用位置保护浏览器扩展使我的位置成为一个固定点。

导致此问题的原因是什么?是因为不是https吗?

如果您想在大多数(如果不是全部)现代浏览器上支持地理定位,则必须切换到 https。

对于Chrome

Starting with Chrome 50, Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections. This means that the page that's making the Geolocation API call must be served from a secure context such as HTTPS.

对于Firefox

This feature is available only in secure contexts (HTTPS) [...]

并且根据 nice support grid on MDN,Opera 和 Safari 也应该需要 https 才能启用地理定位。