IP地址获取当前地理位置(省份)的接口

腾讯的接口是 ,返回数组 http://fw.qq.com/ipaddress
返回值 var IPData = new Array("61.135.152.194","","北京市","");
 
新浪的接口 : http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js 
多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42
返回值 var remote_ip_info = {"ret":1,"start":"218.192.0.0","end":"218.192.7.255","country":"u4e2du56fd","province":"u5e7fu4e1c","city":"u5e7fu5dde","district":"","isp":"u6559u80b2u7f51","type":"u5b66u6821","desc":"u5e7fu5ddeu5927u5b66u7ebau7ec7u670du88c5u5b66u9662"};
 
 
使用腾迅的api接口,php获取ip地址以及所在城市
http://fw.qq.com/ipaddress返回类似:var IPData = new Array("61.51.71.183","","北京市","");
代码 
 
  public static function positionAction($ip) {
        $ch = curl_init("http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip={$ip}");
        //curl_setopt($ch,CURLOPT_ENCODING ,'utf8'); 
        curl_setopt($ch, CURLOPT_TIMEOUT, 10);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 获取数据返回 
        $location = json_decode(curl_exec($ch));
        curl_close($ch);
        if ($location->ret == -1) {
            return [
                'status' => 0,
                'info' => '获取地理位置失败'
            ];
        }
        return [
            'status' => 1,
            'info' => '获取地理位置成功',
            'handle' => $location
        ];
    }

php用淘宝接口获取ip的城市省份

/**
* 通过淘宝IP接口获取IP地理位置
* @param string $ip
* @return: string
**/
function getCity($ip)
{
  $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
  $ipinfo=json_decode(file_get_contents($url));
  if($ipinfo->code=='1'){
    return false;
  }
  $city = $ipinfo->data->region.$ipinfo->data->city;
  return $city;
 }
header("Content-Type:text/html;charset=utf-8");
// 这样调用,显示山东省临沂市
var_dump(getCity("112.234.69.189"));
?>
原文地址:https://www.cnblogs.com/wicub/p/4898169.html