Various internet suggestions I tried before finally arriving at the answer:
- Using window.navigator.geolocation rather than just navigator.geolocation. You should do this (or find a toolkit that abstracts it for you – jquery doesn’t seem to).
- Temporarily changing my DOCTYPE to the HTML5 declaration <!doctype html>. The Microsoft geolocation pages say that geolocation is only supported in standards mode, and that using the HTML5 doctype is the easiest way to do this. However, I could see from F12 developer tools that I was already in IE9 standards mode.
- Changing the IE9 privacy settings. There’s a checkbox to prevent sites from requesting your location; it wasn’t checked, but there’s a “Clear sites” button next to it so I gave that a go. No dice.
- Combing through the security settings to see if there was a magic radio button. Nope.
Finally, I created a minimal page on my desktop with just a hyperlink to invoke getCurrentPosition(). That worked, so I assumed there was something subtly broken in my real page. So, I saved the source to the desktop so I could start butchering it to find the problem. However, when I loaded the unmodified page in IE9, it worked.
So I figured it was something to do with the page’s URL. It was being served on an intranet server, so I used the old trick of using a qualified domain (http://foo.internal rather than http://foo) to trick IE into thinking it was an internet site (it seems that dots in the domain are how IE decides). Lo and behold, that did it, and geolocation started working.
However, that wasn’t the end of the story. It turns out that when IE9 prompts you to ask whether you want to share your location, if you click the ‘X’ close button rather than making a selection, it will no longer prompt you thereafter. Restarting the browser clears it. I then went back to my unqualified domain, and that fixed that too.
TL;DR: try restarting your browser.