j1417
November 3, 2016, 1:49am
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);
});
}
That exact code works fine for me in the challenge .
Can you post all of your code from the challenge? I suspect you haven’t put it between the script tags properly.
j1417
November 3, 2016, 2:12am
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>
That still passes the tests for me.
Try clearing the browser cache and resubmitting that solution.
j1417
November 3, 2016, 2:17am
5
I think that is a problem in Opera. The code works fine in Chrome.
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.
For opera, you can verify your setting here:
Settings > Preferences > Advanced > Network
Is “Allow websites to request my physical location” checked?
j1417
November 3, 2016, 2:27am
8
yes, the option is checked!
Maybe check the geolocation exceptions to ensure you didn’t accidentally block FCC from using the geolocation:
Does your address bar have the blue geolocation icon and the green padlock?
Also, what version of Opera are you using?
j1417
November 3, 2016, 2:41am
13
The blue icon appears.
41.0.2353.46 - Opera is actualized.
When you press Ctrl + Shift + I
and select console
, does it report any errors?
j1417
November 3, 2016, 2:45am
15
Error shown:
Get https://www.google-analytics.com/analytics.js Failed to load resource: net::ERR_CONNECTION_REFUSED
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?
j1417
November 3, 2016, 2:50am
17
I had Adblock but i deactivated.
j1417
November 3, 2016, 3:01am
18
Sorry… the error was previous.
Haha! No worries.
You said before that you have the blue icon - do you have the green padlock icon as well?
j1417
November 3, 2016, 3:03am
20
yes! … the alert is shown for you in opera??