javascriptjqueryhtmlmobile-chrome

ask user to get current location in mobile browser


I have a compass web app which points to the clients store location, and I want to get the users geolocation permission so I can use the two locations.

I found this code in the internet, but it doesn't work in mobile browser

navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "prompt" */
});


navigator.geolocation.getCurrentPosition(function(result) { /* ... */  })

navigator.permissions.query({ name: 'geolocation' }).then(function(result) {
    /* result.status = "granted" */
});

navigator.permissions.query({ name: 'push', userVisibleOnly:true }).then(function(result) { /* ... */ });

Solution

  • Your browser must support this feature

    If you browser isn't exist in this list, that's mean you can't use geolocation:

    https://caniuse.com/#feat=geolocation

    As we see, you need use: