Geolocation does not work [Spoiler]

Geolocation does not work [Spoiler]
0

#1

Hi! Im trying to get the latitude and the longitude from the navigator with the code in the challenge but it does not work:

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

#2

That exact code works fine for me in [the challenge](https://www.freecodecamp.com/challenges/get-geolocation-data#?solution= fccss %20%20%2F%2F%20Only%20change%20code%20below%20this%20line. %20%20 %20%20if%20(navigator.geolocation)%20{ %20%20navigator.geolocation.getCurrentPosition(function(position)%20{ %20%20%20%20%24("%23data").html("latitude%3A%20"%20%2B%20position.coords.latitude%20%2B%20"<br>longitude%3A%20"%20%2B%20position.coords.longitude)%3B %20%20})%3B%0A%7D%0A%20%20%0A%20%20%2F%2F%20Only%20change%20code%20above%20this%20line.%0Afcces%0A%3Cdiv%20id%20%3D%20%22data%22%3E%0A%20%20%3Ch4%3EYou%20are%20here%3A%3C%2Fh4%3E%0A%20%20%0A%3C%2Fdiv%3E%0A).

Can you post all of your code from the challenge? I suspect you haven’t put it between the script tags properly.


#3
    <script>
      // Only change code below this line.
      
      if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition(function(position) {
        $("#data").html("latitude: " + position.coords.latitude + "<br>longitude: " + position.coords.longitude);
      });
    }
  
  // Only change code above this line.
</script>
<div id = "data">
  <h4>You are here:</h4>
  
</div>

#4

That still passes the tests for me.

Try clearing the browser cache and resubmitting that solution.


#5

I think that is a problem in Opera. The code works fine in Chrome. :disappointed:


#6

According to http://caniuse.com/#search=geolocation Opera allows navigator.geolocation from secure (https) servers. Free Code Camp is https, so I can’t imagine what the problem would be.


#7

For opera, you can verify your setting here:

Settings > Preferences > Advanced > Network

Is “Allow websites to request my physical location” checked?


#8

yes, the option is checked!


#9

Maybe check the geolocation exceptions to ensure you didn’t accidentally block FCC from using the geolocation:


#10

Checked that too:cry::cry::cry::cry::cry::cry::cry::cry::cry::cry::cry::cry::cry:


#11

Does your address bar have the blue geolocation icon and the green padlock?


#12

Also, what version of Opera are you using?


#13

The blue icon appears.

41.0.2353.46 - Opera is actualized.


#14

When you press Ctrl + Shift + Iand select console, does it report any errors?


#15

Error shown:

Get https://www.google-analytics.com/analytics.js Failed to load resource: net::ERR_CONNECTION_REFUSED


#16

Interesting…

With a completely clean install of Opera, I don’t get that error when I run the code.

Is it possible that you have some plug-ins installed that block Javascript? Like NoScript or something like that?


#17

I had Adblock but i deactivated.


#18

Sorry… the error was previous.:grin:


#19

Haha! No worries.

You said before that you have the blue icon - do you have the green padlock icon as well?


#20

yes! … the alert is shown for you in opera??