views:

675

answers:

3

hi. i noticed that some websites and some iPhone apps can detect my current geographic location.. i mean the exact latitude and longitude.

how can i integrate these feature in my web application. are there any free open source library that can be used to accomplish this task?

thank you.

+2  A: 

Firefox 3.5 does it out of the box:

http://en-gb.www.mozilla.com/en-GB/firefox/geolocation/

https://developer.mozilla.org/En/Using%5Fgeolocation

In fact the javascript API is the same for Firefox 3.5 and Mobile Safari (iPhone/iTouch). Pretty cool, huh!?

In fact I am pretty certain that geolocation is part of HTML 5 spec.

Igor Zevaka
FWIW, the W3C Geolocation API is _not_ part of the HTML5 spec, it just happens that it's also being developed at the same time.
npdoty
That is of course correct. I mixed the two up.
Igor Zevaka
+1  A: 

iPhone apps by and large do it via Apple APIs which use the cell-phone positioning data and GPS (if available). Websites just map the IP range to an area/zip code based on some whois, and other accumulated information. The former is obviously much more accurate, but neither is perfect.

If you find a free API that lets you do the later, I would be very interested, as it is easy to find services which will do this for a fee, but I don't know any that will do it for free (at least probably not for commercial use)

nosatalian
+5  A: 

Native iPhone apps use CoreLocation, which will take advantage of GPS, cell tower triangulation or Apple's/Skyhook's database of WiFi access point locations to detect the user's exaction location. (Incidentally, native Mac apps on Mac OS X 10.6 and higher also have access to CoreLocation.)

Web sites that use the W3C Geolocation API can also request your location -- on Mobile Safari this uses CoreLocation under the hood, but it can be implemented by different browsers in different ways. As Igor points out, Firefox 3.5+ can respond to Geolocation requests (they use WiFi network IDs that they send to Google).

The W3C Geolocation API is still in draft form, but the Javascript is very simple to use. Read the samples on the spec page, or you can look at my test site (which also explains IP geolocation -- another technique that isn't quite as precise).

npdoty