views:

1532

answers:

4

What is the best way to get geo-location in Java (freely if possible)?

Update: Not from a GPS device. Basically how Firefox 3.5 / HTML 5 does it

A: 

The biggest database of WiFi-to-location is probably SkyHook Wireless, used by Apple and Google for their geo-location. There are SDKs available - see http://skyhookwireless.com/developers/.

Isaac Waller
It seems to be for C++, is there a Java version ?
srand
If you want to use that, you can probably use JNI to call the native C++ code, however that will probably reduce the cross-platform abilities of your Java application.
Thomas Owens
These days JNA should be used instead of JNI
Thorbjørn Ravn Andersen
+1  A: 

If you need a local database, you can check out what IPInfoDB has to offer.

If you can use a web service, there are a number out there, but I'm not sure what their Terms of Service allow. A Google search for "ip geolocation lookup web service" turns up some stuff, but many of them are commercial products and you would have to read their ToS carefully to make sure you use them within the guidelines.

Thomas Owens
"Over 99.5% on a country level and around 80% on a city level for the US within a 25 mile radius. The database used for this API is compiled from the free Maxmind CSV database (Geolite City) and rearranged with many scripts."Hm, seems to get the city right, Google maps does it pretty accurately, only off by a mile or so.
srand
Of course, you would need to periodically update your CSV or SQL files with IPInfoDB. But it's all about tradeoffs. Manual updates of the IP databases versus being able to hammer it with queries.
Thomas Owens
A: 

If you want to know how Firefox 3.5 (or Google Chrome) gets the geolocation, then please take a look here: How Google/Firefox Geolocation API works

Basically, what Firefox 3.5 (as well as Chrome) does is to get the list of nearby Wi-Fi networks and send that list using JSON to a Google webservice, which will then return the approximate coordinates.

By the way, there is no Java involved in this process. To get geolocation from Firefox/Chrome, you just call a few JavaScript methods. (I really hope that you know that Java is different from JavaScript)

Denilson Sá
+1  A: 

If I understand well enough, you want to get the geographic location of visitors to your site or web application. The alternatives I know are:

Google Gears has some functions to make GeoLocation(http://code.google.com/apis/gears/api%5Fgeolocation.html), but need to install Gears

Using JavaScript functions that call an online service such as IP Location Tools (www dot iplocationtools dot com). The site has examples and even have a video tutorial.

Mig