Question on Geolocation API re mobile browsing

Hey guys! First time posting on the forum, getting really stuck on a problem and haven’t found any answers searching online or through the forum. I am able to get the HTML5 geolocation API to work fine on a desktop browser, but a mobile browser requires multiple page refreshes before the success callback gets triggered. What’s odd is that the error callback doesn’t even get triggered even after waiting well past the timeout value. Please note that the page looks like a turd sandwich at the moment, very spartan until I can solve this geolocation issue - just a div’s innerHTML being updated to the temperature that the API sends back. Would appreciate any tips, thanks!

I’m looking into your geolocation issue, but I know very little about APIs and mobile in general, so I’m not sure I’ll be able to come up with anything for you. However, I do want to point this out:

function setLatLong(position) {
  myLatitude = position.coords.latitude;
  myLongitude = position.coords.longitude;
  requestDarkSky(myLatitude, myLongitude);

function requestDarkSky(lat, long) {
  var request = document.createElement('script');
  request.setAttribute("src", "" + myKey + "/" + myLatitude + ',' + myLongitude + "?callback=updateTemp");

You’ve gone out of your way to designate a pair of arguments for your requestDarkSky function (“lat” and “long”), but then you don’t even use them at all. Instead, you set myLatitude and myLongitude as public variables and used them as such. Is this deliberate?

EDIT: “Connection timed out” appears correctly on my mobile device (I have location tracking set to off).

Thanks for the tip - you’re right, since I was using globals I didn’t need to include them. I went ahead and removed the arguments and everything still talks.

As far as mobile browsing, I think I’ve noticed that it has only been mobile safari behaving the way I described. Mobile chrome seems to not need multiple manual page refreshes.

Thanks for your help!

Well, I’m not sure I was much help at all, but for what it’s worth, I’m using mobile safari.

Good to know the error callback works if location services is off. Are you able to test it with it turned on? Curious to know what happens for you if location services was on.

I’m afraid not. Good luck sorting out the bugs though!

Going to try the IP geolocation API, see where that goes.

Don’t forget to always try using both http and https protocols. That was probably the biggest reason for me not being able to get things to work right during the API challenges.