Search code examples
phpgeolocationlocationmaps

Location and region finding from the user ip address


Am using this code for getting the location of the IP address.

$location = file_get_contents('http://freegeoip.net/json/'.'117.253.168.187');

Here is my problem when i provide the ip address as 117.253.168.187 country is listing as proper IN but the region is return empty value.

{"ip":"117.253.168.187","country_code":"IN","country_name":"India","region_code":"","region_name":"","city":"","zipcode":"","latitude":20,"longitude":77,"metro_code":"","area_code":""}

If i change the ip as 122.166.65.125 its return the proper region with country.

{"ip":"122.166.65.125","country_code":"IN","country_name":"India","region_code":"19","region_name":"Karnataka","city":"Bangalore","zipcode":"","latitude":12.9833,"longitude":77.5833,"metro_code":"","area_code":""}

I don't know why this api showing empty regions in some IP address ??

I have a redirect in my page depends on the region. So how can i solve the region issue ??

am collecting dummy ip address from INTERNET eg:http://myip.ms/view/cities/67445/IP_Addresses_Cochin.html

Anyone can help me for finding solution.


Solution

  • This is because my be freegeoip.net does not have complete region information for IP 117.253.168.187. I have also tried lots of ip to location but only paid one works fine. You may use http://www.ip2location.com/demo