Question

I want to put together a PHP script to resolve city name (nothing else is needed) with a good resolution just for a single country (IRAN). As I have to query the DB for multiple times, its better to go through a downloadable local version. I have read most of posts on stackoverflow and since now I have tested these:

  • GeoIP City from maxmind sounds good, but is not free.
  • GeoIP from maxmind, has a low level of accuracy (about 50-60%)
  • ip2country.net has an IP-2-City Database but not free and does not resolve city names for Iran.
  • I also tried the DB#.Lite from ipinfodb.com which has an API here without any success. The problem is that, it does not detect many city names.
  • I also tried hostip.info API, but it seems to be too slow.
  • There is a free php class with local DB which resolves only the country name.
  • I dont know if there is chance, using Piwik with this GeoIP plugin. It would be appreciated to have ideas if someone knows about it.
  • ipinfo.io is another service which does not resolve city names with accuracy.
  • I dont know if there is a way to use Google analytics to resolve city names, as I think google would be better than any other service regarding countries like Iran.

Any good idea would be really appreciated.

Was it helpful?

Solution

This is a tough one and hard to do reliably. I have given it a go in the past and it went something like this

There are paid for services that can do this really quickly for you. It might take you ages to get something working that is still unreliable because you simply do not have the data. I would seriously consider http://www.maxmind.com/en/city_per - unless of course this is a completely none commercial project and $ is a no no.

If you can get the lat and long from an IP table, even without the city data then you may want to then use something like this to check for the nearest city of Javascript is an optio n - Finding nearest listed (array?) city from known location.

What about the browsers Share Location feature?

OTHER TIPS

If a browser-based solution works for your use case, you might want to look at MaxMind's GeoIP2 JavaScript API. It first attempts to locate the user using HTML5 geolocation and if that fails or is inaccurate, it reverts to MaxMind's GeoIP2 City data (not GeoLite). MaxMind provides a free attribution version.

Sometimes we need to use local Geo-IP database instead of web services for particular purposes. This is my experience: I downloaded database form https://db-ip.com. I was searching a lot and finally I found this one more reliable. but still two more problem:

  • 1-The "IP address to city" database is too huge to upload on MYSQL database on hosting as it pass time out limit.
  • 2-The Database is base on IP address compare of http://lite.ip2location.com Database is base of IP Numbers.

So I developed a simple .NET app to solve those problems. The solution can be downloaded from here: https://github.com/atoosi/IP2Location-Database-Luncher

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top