Google chrome taking extremely long to show location? Codepen?

I am currently working on the local weather intermediate project. It is very frustrating, because google chrome has been taking extremely long to display my location when I allow access. I know the function is working, because I console.log it as well. No matter if I write it locally on my computer or if I write it on codepen, both either don’t display the location for a very long time, when I check back on the page 20-30 mins later, or just doesn’t show it at all after 30+ min, even though everything is working correctly, functionality wise.

Very rarely it will show instantly. Maybe one out of 30 tries it will show as soon as I load the page.

A few days ago, codepen was taking very long to show the location. When I wrote the file locally, it was showing the location instantly. Now, neither is working.
Tried on 2 different computers as well. I’m starting to think it has something to do with chrome? Has anyone else experienced this issue?

Just for clarification, this is my JS

var latLong = document.getElementById("latLong");

var lat = document.querySelector("#lat");
var long = document.querySelector("#long")

function myPosition (position){
  lat.textContent  =  position.coords.latitude;
  long.textContent  = position.coords.longitude;
}




if (navigator.geolocation){
  navigator.geolocation.getCurrentPosition(myPosition)
  console.log("showing location ")
}
else {
  latLong.innerHTML = "sorry, position not avaliable"
}



Yes, navigator is taking a ridiculous amount of time, especially on repeated calls. Either hardcode in lat and lon for now, or use an api to get lat and lon.

I wrote this pen to illustrate the problem.

Ah glad it wasn’t just me. Is this normally the case?

I haven’t started the project yet really, which is why I am just trying to get the coordinates right now to make sure I understand.

Reason I was doing this to get the coordinates is because I was then going to pass in those variables to the api URL, in order to fetch the correct JSON data. Does that sound like something that would work?

I don’t know, but running my pen in different browsers, after the first call, the navigator seems to limit the time (20 seconds in chrome, 6 seconds in ff) but sometime takes significantly more. I don’t know why, but tha’s what it seems to do.

Is it the right way to get the coords? Sure. It just doesn’t like being called repeatedly. That’s why I suggested hard-coding the coords for dev. Someone else mentioned saving them in local storage for sunsequent requests, while waiting for new coords. Or there are APIs that can get coords off the ip address.