I must be doing something wrong here, but I can't find what... I'm making a page for my company website that, among other things, provides directions to job sites based on the user's current location. To get their location, I'm using the Geolocation API as implemented in Firefox (I was testing with FF9 and now FF10). For the moment I'm testing with the sample code that is in the Wikipedia article:
<html>
<head>
<title>Geolocation Test</title>
<script type='text/javascript'>
var gl;
function displayPosition(position) {
var p = document.getElementById("p");
p.innerHTML = "<table border='1'><tr><th>Timestamp</th><td>" + position.timestamp +
"<tr><th>Latitude (WGS84)</th><td>" + position.coords.latitude + " deg</td></tr>" +
"<tr><th>Longitude (WGS84)</th><td>" + position.coords.longitude + " deg</td></tr></table>";
}
function displayError(positionError) {
alert("error " + positionError.code);
}
try {
if (typeof navigator.geolocation === 'undefined'){
gl = google.gears.factory.create('beta.geolocation');
} else {
gl = navigator.geolocation;
}
} catch(e) {}
if (gl) {
gl.getCurrentPosition(displayPosition, displayError);
} else {
alert("Geolocation services are not supported by your web browser.");
}
</script>
<body>
<p id='p'></p>
</body>
</html>
(copy/paste this into a text editor, save as "whatever.html", and drag the file to the browser to open it)
Very simple code, and it actually worked fine last Thursday, 01/26/12. (I know, I know, people say "It worked yesterday!" when they actually goofed something up, but I swear it really did.) Since then, however, it's been giving me error code 2, "POSITION_UNAVAILABLE". I have tried it with my work computer on my work network, my work and home computers on my home internet connection, and my work computer on a wifi hotspot from my phone, and it gives error code 2 every time.
I thought maybe I'd somehow goofed something up in my browser or my network settings or something (though I couldn't imagine what), so I tried the next test, which everyone should be able to do:
- Go to maps.google.com.
- Search for "seattle" (or some other location, whatever).
- Click the "Get Directions" button.
- In the directions boxes on the left, "A" should say "My location" and "B" should say "seattle". (If it doesn't say "My Location" in A, type "m" into the box, and the auto-populating dropdown will usually have "My Location" as the first option.)
- Click the "GET DIRECTIONS" button.
- Firefox should pop up a message saying maps.google.com wants to know your location. Click "Share Location".
- After a couple seconds, it should either show you directions from somewhere (wherever it thinks your server is) to Seattle, or the "A" box should go blank and it'll say "Could not find your location" or similar toward the top of the map.
And here's the weird thing: I have never yet gotten this to work on any computer. My work computer (on both FF10 and Chrome), my coworkers' computers, my home computer, and my GF's work computer all do the same thing; none can find the location.
So my question is: Is the location API down or something, or am I screwing something up? I haven't been able to find any indications online of an API outage, and it seems like an outage is very unlikely, but if so, why does it not work on any computer I've tried it on? Can anyone else duplicate these findings or know what I'm doing wrong?
Thanks!