I am using HTML5 Geolocation feature. My code is well running in 'localhost' but problem in 'subdomain' .My code below:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
console.log("Geolocation is not supported by this browser.");
}
In most cases, localhost will be treated as a secure URL regardless of HTTP or HTTPS connection. This is to ease the development process and allow you to make use of features that would only be accessible through a secure connection.
However, if you are still having issues with this on localhost or want to access the website remotely via HTTP with geolocation enabled, the following steps should set you up:
Download chrome and paste the following URL into your address bar chrome://flags/#unsafely-treat-insecure-origin-as-secure
.
On that page locate the Insecure origins treated as secure
flag and add the URL which is failing to load the geolocation in the text box. e.g. example.com
or localhost
in your case.
Once you've added it, select enable on the right-hand side.
Click the reload changes button and then revisit the website, it should now ask for geolocation.
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