I've created an extension and I'm trying to get the user's location so I can display it to them.
I've tried adding this code:
var x = document.getElementById("ua");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Unavailable.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
But nothing comes up in the extension, any advice? I'm also trying to avoid using the Chrome location API as it is only available on the Dev Channel.
The Declare Permissions page in the documentation lists a special permission for your case:
"geolocation"
Allows the extension or app to use the proposed HTML5 geolocation API without prompting the user for permission.
You must use it, because the permission infobar cannot be shown for some extension pages (background, popup).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With