Page 1 of 1

How to retrieve latitude and longitude for each user using MaxMind GeoIP with SmartFoxServer?

Posted: 26 Jan 2025, 17:40
by ciaoamigos
Hi everyone,
I’m working on a project based on SmartFoxServer, and I need to retrieve the latitude and longitude of each user connected to the server. I read that it’s possible to use the com.maxmind.geoip library to get geographical information based on the user’s IP address.

My questions are:

How can I properly configure SmartFoxServer to use MaxMind GeoIP?
Is it possible to retrieve the geographical coordinates (latitude and longitude) of each user during login or at a later stage?
Are there any practical examples of integrating com.maxmind.geoip with SmartFoxServer to access geographical data?
Currently, I know I can use user.getIpAddress() to retrieve the user’s IP, but I’m unsure how to convert it to coordinates using MaxMind.

Thanks in advance for any help!

Re: How to retrieve latitude and longitude for each user using MaxMind GeoIP with SmartFoxServer?

Posted: 27 Jan 2025, 09:16
by Bax
Hello.
SmartFoxServer integrates MaxMind GeoLite2-Country database, which doesn't include detailed data like city, longitude, latitude, etc.
You can download your own version of GeoIP database from MaxMind's website and query it using the MaxMind Java API already distributed with SmartFoxServer. Instructions on how to query the database are available here: https://dev.maxmind.com/geoip/geolocate ... databases/ (check step 2 only, as the library is already contained in SmartFoxServer's lib folder and you don't need to download it again)

Re: How to retrieve latitude and longitude for each user using MaxMind GeoIP with SmartFoxServer?

Posted: 28 Jan 2025, 06:56
by ciaoamigos
I need to access the headers['cf-iplatitude'] and headers['cf-iplongitude'] headers, which are specific headers added by Cloudflare. How can I retrieve these headers on a SmartFoxServer instance? Is there a specific configuration or method to access these Cloudflare-provided headers in SmartFoxServer?

Re: How to retrieve latitude and longitude for each user using MaxMind GeoIP with SmartFoxServer?

Posted: 28 Jan 2025, 07:39
by Lapo
Hi,
there is no specific mechanism to read those headers.
Those custom headers are only relevant for the HTTP protocol, while SFS2X works mainly with TCP and UDP.
When using Websockets there is an initial HTTP exchange that switches the connection from state-less to stateful (i.e. the UPDATE request), but we don't have a mechanism to grab custom HTTP headers at that stage.

Cheers