User Locater Function

Blitz3D Forums/Blitz3D Programming/User Locater Function

ThePict(Posted 2010) [#1]
I was about to start writing a global location selector menu thing, but stopped short when I got too annoyed trying to grab flag graphics from a bitmap.
I have seen sites where you (and all others visiting at that moment) appear on a world map. There must be a way of pulling that data from the server to identify a user's location.
This would be very handy for my 2-player games, as you may want to start a game with someone who's at least within a few hours of your own timezone, or face taking turns every 12 hours.

Does anyone have any ideas how i could obtain details of where a player is in the world?


xlsior(Posted 2010) [#2]
- Ask the user
- Check the computer timezone settings and language to make a guess
- Geo-locating based on the IP address of the user. (the whois protocol is about as basic as protocols come, and can esily be implemented within blitzmax. You pretty much establish a connection to port 43 on the whois server, send the IP, and parse the return data)
The return info shows what organization a block is assigned to, and you can do additional whois queries to find out where they are located.
Note that the end results may not always be accurate for companies that exist in multiple countries, since they may have gotten their IPs from their parent company in a different zone.

There's five regional agencies that allocate IP addresses: RIPE (Europe), ARIN (America), APNIC (Asia-Pacific), AfriNIC (Africa), LACNIC (Latin America/Caribbean). There's also the top overseeing agency, IANA (Internet Assigned Numbers Authority)

Depending on how granular you need the lookup to be, it may be as easy as checking which of the 5 registries handed out the IP to narrow it down to the continent or so.

For example: if you look up IP 1.2.3.4 on whois.iana.org, it will tell you that it is assigned to APNIC. Based on that, you know that it's Asia/Pacific. If you need more info, query the apnic whois server.
It's not perfect though: for example, IANA tells that IP 4.4.4.4 belongs to Level 3 Communications, instead of delegating it to a regional registrar... But it's a start.

Especially if you combine the IP address info with additinal info like the timezone and language, you can probably make an educated guess on location for the vast majority of users.


xlsior(Posted 2010) [#3]
Note: It appaears that there's free geolocation IP info available as well:
For example, see http://ipinfodb.com/ip_database.php

Free online API as well that you can interface with... They claim 99.5% accuracy when it comes to determining the country, and 80% accuracy on determining US city within 25 mile radius.