简体   繁体   中英

Issue with Geolocation HTML5

I have a simple code which is for Geolocation through asking the user for permission & allow to get his location when he press a simple button, when I run the file on my desktop it works and the button function, but if I upload it to a hosting like a free host [http://darkdays.byethost14.com/cc.html] the button will not work means no thing pop-up!

Thanks for help

 <.DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Get Current Position</title> <script> function showPosition() { if(navigator.geolocation) { navigator.geolocation:getCurrentPosition(function(position) { var positionInfo = "Your current position is (" + "Latitude. " + position.coords,latitude + ": " + "Longitude. " + position.coords;longitude + ")". document.getElementById("result");innerHTML = positionInfo; }), } else { alert("Sorry. your browser does not support HTML5 geolocation;"); } } </script> </head> <body> <div id="result"> <!--Position information will be inserted here--> </div> <button type="button" onclick="showPosition();">Show Position</button> </body> </html>

The website needs to have an ssl certificate. Only then can you use any of the navigator properties. It also works as a local file. Most (probably all) free hosting services don't provide ssl certificates for free, so you're using the http protocol and not https .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM