Android Question Get city/state location from IP-address

siddsg

Member
Licensed User
Longtime User
Hello,
I've gone thru the earlier posts and should be able to get IP address (not tried it yet, but there are many posts for it so should be do-able).

Once I get a device's IP-address, how can I detect the city/state location?

I am basically working on a multilingual app where relevant content can be shown in local languages based on a person's location. I live in a country with 22 official languages!

Since it is broad content like languages that are changing, I don't want exact location services like GPS.

Thanks,
Sidd
 
Last edited:

siddsg

Member
Licensed User
Longtime User
Hello,
Researched this a bit...and here is one method I found...
There are firms that publish (free and paid) databases that give locational information based on IP-address.

One that I found:
http://dev.maxmind.com/geoip/legacy/geolite/

These guys have downloadable csv files, where IP-address allows you to mapped to Country, region, city.

Downside:
Only city info seems to be there. If I'm in a smaller town or village, info is not there...atleast in the free download csv.
Maybe more detailed small town/village info is there in the paid one.

Hope this is useful for those of you trying to make a similar app!

Thanks,
Sidd
 
Upvote 0

DouglasNYoung

Active Member
Licensed User
Longtime User
Siddsg,
Sorry, not an answer to your question, but..... It is a bold assumption to base a default language on location. I live in France and get realy pissed off by sites that assume that I want the language as French (I'm a native English speaker). Imagine any cosmopolitan city, probably about half natively speak a language other than the country's native language!

Douglas
 
Upvote 0

ggpanta

Member
Licensed User
Longtime User
As mentioned you could use the maxmind db but you would need to either include the csv (both ipv4 and ipv6) in your app or create a web app that will serve you the results (ie post the ip to a php script on your server, do the lookup and return the string). But you should know that you cant just lookup the IP you will get from the device, you need to make sure
a) you will get the correct one, the phone will have an IP in a private range most probably even on gsm so nothing too lookup there, you will need again to depend on an external service (lots of those available and ofc its easy to just have a php script to give you the IP of the phone on a simple post to it)
b) the max mind DB's include IP ranges, not a full list of IP's ie 192.168.1.0 - 192.168.1.255 if you are lucky or a class like 192.168.1.0/24 which makes queries even more difficult

I would just propose you just check the phone locale, many users prefer to have the language they have selected on the phone, I am greek but I still have my phone on the en.US locale cause I prefer it.
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…