Local Weather API - issues with navigator.geolocalisation

Local Weather API - issues with navigator.geolocalisation
0

#1

Hi guys,

Im wondering why the navigator.geolocalisation function didnt provide me the lat and long of my browser.
The code is exacly the same than on FFC lesson, and on the lesson it works, on code pen it didnt.
Anyone could help ?

http://codepen.io/steffanek/pen/amgLag

HTML part :
<div id="data"></div>

JS part :
$(document).ready(function(){

    if (navigator.geolocation) {
      
      navigator.geolocation.getCurrentPosition(function(position) {
        $("#data").html("latitude: " + position.coords.latitude + 
"<br>longitude: " + position.coords.longitude);
      });
    }  
  
      
    });

#2

geolocation doesn’t work because you need to use a secure connection ( https ). Trying your code on https://codepen… the browser ask me to allow the geolocalization and if I authorize it your code works.

– Note: this is the message in the chrome console which explain that.
getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS. See https://goo.gl/rStTGz for more details.

( Sorry for my english :stuck_out_tongue: )


#3

Yes thanks I got it ! :slight_smile: