简体   繁体   中英

Get zip Code from IP address or Latitude / Longitude in PHP

Below code works to fetch latitude / longitude from IP address but it doesn't provide zip code.

$str_arr_ipdat = @json_decode(file_get_contents("http://www.geoplugin.net/json.gp?ip=" . $_SERVER['REMOTE_ADDR']));
if(!empty($str_arr_ipdat)) {
    $str_latitude = $str_arr_ipdat->geoplugin_latitude;
    $str_longitude = $str_arr_ipdat->geoplugin_longitude;
} 

So is there any other free / paid service using which I can get zip code from ip address or latitude / longitude? I have referred many similar questions here but they are too old and some of links for services are not working now days.

Also how accurate will be this free / paid service to get zip code from IP address or latitude / longitude?

Please advise, Thank You

Precision of IP-based location is in the several miles range. The most you can get from IP address is the location of ISP providing the service, usually in the form of city/state. Large cities have hundreds of Zip codes in them. If it's a small city, the ISP probably serves several of them.

So the short answer is no, you cannot get Zip code from IP address with any meaningful precision.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM