Reputation: 4151
How do get the longitude and latitude on a Windows PC?
I'm writing a libgdx game, and I'd like to make multiplayer matchmaking based on location. I already get the location on android, but I need to get it on the desktop version. I've had a hard time finding an answer as most answers are written for android.
I don't need exact accuracy, but, it would be nice if it could accurately determine city/county.
Google maps API is something I've seen around, it sounds like it does more than I need, and it doesn't seem to have a version for java(that isn't for android..)
Edit: I am really just looking for an reliable IP > location service, for java. (I'd like about 50-200 miles accuracy). And free if possible.
Upvotes: 0
Views: 4054
Reputation: 5126
Make an http request to http://www.geoplugin.com/ service, is free but not it's not locality 100% accuracy.
It will give you the location by ip.
P.D.: In your case you should use jsonRequest via java to http://www.geoplugin.net/json.gp?ip=xx.xx.xx.xx Documentation: http://www.geoplugin.com/webservices/json
===================================================
You have other alternatives like (more accuratted sometimes): - http://www.iplocation.net/ (must parse html for results) - http://whatismyipaddress.com/ip/xxx.xxx.xxx.xxx (must parse html for results) - http://www.ip2location.com/ (non-free?)
Upvotes: 1
Reputation: 15199
For Windows 7 and up, you can use the Windows Location API. It isn't exposed in Java, but it should be fairly simple to write a program in a language that can talk to it (e.g. C#) and then call out to that program to get the data. It is reasonably likely that a PC won't actually have any useful idea of where it is, however, as most (at least for now) do not have built-in GPS hardware.
Upvotes: 1
Reputation: 168845
I'd like to make multiplayer matchmaking based on location..
Since the player has a motivation to supply that information, one good method is to just ask them.
Upvotes: 1
Reputation: 1413
You can only get an approximate location probably only country by using IP address. Check Google Maps API v3 - IP-based Geolocation for what you can do using google maps api. There are many apis and services out there btw.
Upvotes: 0