apachehttpbrowsergeolocationleaflet

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


I have made this application using Leaflet.js with these plugins: MarkerCluster, Leaflet Map Fullscreen, it's hosted in a Linux server, HTTP apache2.

For some reason, I can't get my current location on the following browsers:

In IE, it gives me the popup to give permission to locate myself, and it works... only once. If I try to locate myself again it behaves like the other browsers above.

And, if I open the link in Instagram dm's it works just fine...

request to get current locationand locates just fine

It works also in localhost or if I use location guard browser extension to make my location a fixed point.

What's causing this issue? Is it because it isn't https?


Solution

  • You will have to switch to https if you want to support geolocation on most if not all modern browsers.

    For 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.

    For Firefox

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

    And according to the nice support grid on MDN, Opera and Safari should also require https to enable geolocation.