0

I know how to use the W3C navigator.geolocation API, but just found out that under Google Chrome it does not work when the page is on the local filesystem rather than on a web server: [1], [2].

What other techniques can I use to get either the latitude and longitude, or the country code for my current location?

(I'm running my project from the local filesystem because ideally it won't require a server of its own. In fact I don't even have my own domain or hosting or such (hitchhiking around the world with my netbook for the past year). It calls web APIs on 3rd party servers but doesn't have its own server.)

(Yes I know I can work around this by running a local web server such as Python's SimpleHTTPServer, but let's assume for this question that such a workaround is not possible.)

Community
  • 1
  • 1
hippietrail
  • 15,848
  • 18
  • 99
  • 158

1 Answers1

0

If you could turn on cross-domain requests for ajax (such as if you're developing this to run locally on a mobile device) you could make an ajax request to your server and then geolocate the global IP address coming from it. Geolocation is occasionally not accurate (for example, I'm in Utah and my phone's IP comes up in Oklahoma).

You could also redirect the user to a page hosted on another server and do the same thing and then forward them back with the GPS coordinates in the query string.

Both of these are a little ugly, but I don't know really of any way other than geolocation to get GPS coordinates.

Benjamin Oman
  • 1,654
  • 1
  • 17
  • 19
  • The second suggestion assumes that you can redirect to your local web page from a global web page, which may not necessarily be a good assumption. – Benjamin Oman Aug 11 '12 at 11:32
  • Actually this project won't have a server. I don't have an IP or domain hosting or anything of my own. I like to make single HTML page tools which call web APIs (-: I would've tagged the question to make this obvious but there seems to be no such tag )-: – hippietrail Aug 11 '12 at 11:33