0

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.

csga5000
  • 4,062
  • 4
  • 39
  • 52
  • i don't think so can make it, except IP address able to categories by country only. – John Walker Jul 08 '13 at 16:29
  • 2
    Contrary to phones (that can use cell id, gps location), desktops don't have any idea of where they're located. There's a couple of IP to location services (check some out [here](http://www.iplocation.net/)) but their precision is in the miles to 10's/100's of miles range... – fvu Jul 08 '13 at 16:31
  • @fvu That's not entirely true; if you're using HTML5 geolocation, the user can choose to give the running script access to a more precise location. Of course, I'm not sure how you would access that through a Java script. – Kevin Ji Jul 08 '13 at 16:34
  • @mc10 afaik all geolocation stuff for desktops, be it html5 or windows based will need some help to remember your location (ff plugin, default values, whatnot). Ergo, the more sensible thing to do is probably to just ask the user their location and save it as part of the app's settings, bypassing any external services. – fvu Jul 08 '13 at 16:57
  • @fvu I don't mind inaccuracy, I'd just like accuracy up to like 100-200 miles. – csga5000 Jul 08 '13 at 20:54
  • @csga5000 then I'd go with some IP location service, except for some freak cases they'll do the job, without asking for any action from the user. – fvu Jul 08 '13 at 22:59

4 Answers4

1

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

(HTTP Json requests in Java?)

===================================================

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?)

Community
  • 1
  • 1
surfealokesea
  • 4,971
  • 4
  • 28
  • 38
  • I pugged in my IP address, and it was pretty far off, and entire state off, I'd like to get city type accuracy. – csga5000 Jul 08 '13 at 20:37
  • So far yours seems to be the best free option, even though it's not quite as accurate as I'd like.(I would have preffered 50-200 miles, but it was 500 off for me..) – csga5000 Jul 08 '13 at 21:25
1

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.

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • That's not very professional. I know it's possible, and for the most part uses IP's to determine the location on desktops – csga5000 Jul 08 '13 at 20:33
  • Players could lie and much more easily spoof any location if you do this. – Ryan Amos Jul 08 '13 at 20:44
  • @RyanAmos What's the point in doing that tho? It just means you'd end up being paired with chinese people or something... – csga5000 Jul 08 '13 at 21:23
  • Not sure, it really depends on your application. If you treat players from regions differently or give any region based reward, there's a risk it will be abused. – Ryan Amos Jul 09 '13 at 02:15
1

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.

Jules
  • 14,841
  • 9
  • 83
  • 130
0

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.

Community
  • 1
  • 1
Gorky
  • 1,393
  • 19
  • 21
  • Yeah, I was pretty sure I would be approximate, but that's good enough for the desktop version – csga5000 Jul 08 '13 at 20:33
  • As a heads up, you will be capped in the number of lookups per day that you can do (and overall) if you use the free service. – pickypg Jul 09 '13 at 05:09