1

I am trying to use geolocation in my local HTML file. But it looks like, navigator.geolocation.getCurrentPosition only works with https. I don't know how could I use it in my local HTML file for learning.

answerhua
  • 43
  • 1
  • 5
  • 2
    Possible duplicate of [HTML 5 Geo Location Prompt in Chrome](https://stackoverflow.com/questions/5423938/html-5-geo-location-prompt-in-chrome) –  Nov 19 '17 at 07:14
  • For me it works with `file:///` i asume it works with `http://localhost` too. Do you get an error? – Roland Starke Nov 19 '17 at 07:19

2 Answers2

1

A quick solution would be to use a tunneling service like ngrok. Running ngrok http 12345 with 12345 being your local server port will spin up a tunnel and give you the URL you need to access the tunnelled version of your webserver. ngrok offers both HTTP and HTTPS.

Niklas Higi
  • 2,188
  • 1
  • 14
  • 30
0

It seems that chrome has security restrictions on accessing geolocation data locally. You need to host the file to use the data..

Andrii Pryimak
  • 797
  • 2
  • 10
  • 33