Server context client location issue

What I’m trying to do:
I am trying to test localization settings in my app using a VPN to access the app from different countries.

What I’ve tried and what’s not working:
With the VPN in place, my IP address correclty shows me in e.g. Sweden, but a server side call of

anvil.server.context.client.location.country_code

returns “NZ” instead.

Are you running it in the same tab as the IDE? Try running it in another tab with the VPN on, that usually runs more purely than the IDE.

It is not related to the IDE. In another tab, even in another browser, anvil.server.context.client.location.country_code gives me (albeit quite consistently) NZ when whatmyipaddress.com shows correctly Sweden.

Doing some web searching, it looks like the country code reported by the browser isn’t always based on the IP address. Apparently it sometimes uses geolocation? Try turning off geolocation in your browser and try it again, and see if it still reports NZ. That’ll at least narrow down if that’s the issue.

2 Likes

Even with geolocation off, whatsmyipaddress shows correctly Sweden while anvil.server.context.client.location.country_code returns NZ.

I took a closer look at what anvil.server.context.client returns, and the ip address it gives is indeed correct - checking it evaluates to Sweden, as it should be, but the location deduced from that ip is incorrect:
{‘type’: ‘browser’, ‘ip’: ‘130.195.218.20’, ‘location’: {‘city’: ‘Wellington’, ‘subdivision’: ‘Wellington’, ‘latitude’: -41.286, ‘longitude’: 174.7719, ‘country_code’: ‘NZ’, ‘country’: ‘New Zealand’}}

(I used the serialization routine suggested in another thread to log the contents.)

Hope that helps in narrowing down the issue.