I am getting this error on my website which requests Geolocation data from the user:
getCurrentPosition() and watchPosition() are deprecated on insecure origins, and support will be removed in the future. You should consider switching your application to a secure origin, such as HTTPS. See goo.gl/rStTGz for more details.
I mean its basically just a notice, and the google link just says its being deprecated.
I have no plans on moving my website to SSL... so is there an alternative for someone like me?
Give some time to install an SSL cert
getCurrentPosition()
andwatchPosition()
no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS.Use
FireFox
or any other browser instead ofChrome
if you want to test it on your development environment, for production there is no way except usinghttps
.For development environment just open
http://localhost:8100/
on FireFox and alas no such error.Because switching to HTTPS can be painful or impossible depending on your architecture, I found a workaround solution: you can use the Google Maps Geolocation API. Although it has usage limits, it does the job. You will need an browser API key, so don't forget to limit it's usage to your page hostname.
I use it as a fallback method to the
getCurrentPosition()
method if it fails. It allows me to make it work until I switch to HTTPS.Here's the JSFiddles:
getCurrentPosition()
will fail and fall back to the APIgetCurrentPosition()
will succeedYou can run chrome with the --unsafely-treat-insecure-origin-as-secure="http://example.com" flag (replacing "example.com" with the origin you actually want to test), which will treat that origin as secure for this session. Note that you also need to include the --user-data-dir=/test/only/profile/dir to create a fresh testing profile for the flag to work.
For example if use Windows, Click Start and run.
In HTTP the error occurs.
Set permission for localhost in bellow label(Accept requests from these HTTP referrers (web sites)).
It worked for me.
I know that the geoLocation API is better but for people whom can't use an SSL, you can still use some sort of services such as geopluginService.
as specified in the documentation you simply send a request with the ip to the service url
http://www.geoplugin.net/php.gp?ip=xx.xx.xx.xx
the output is a serialized array so you must need to unserialize it before using it.Remember this service is not very accurate as the geoLocation is, but it is still an easy and fast solution.