黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
echo $_SERVER['HTTP_HOST'];
//echo $_SERVER['REQUEST_URI'];
$getIp=$_SERVER["REMOTE_ADDR"];
echo 'IP:',$getIp;
echo '<br/>';
$content = file_get_contents("http://api.map.baidu.com/location/ip?ak=YWNt8VcHK7Goj1yljLlMVHnWl6ZWS26t&ip={$getIp}&coor=bd09ll");
$json = json_decode($content);
echo 'log:',$json->{'content'}->{'point'}->{'x'};//按层级关系提取经度数据
echo '<br/>';
echo 'lat:',$json->{'content'}->{'point'}->{'y'};//按层级关系提取纬度数据
echo '<br/>';
print $json->{'content'}->{'address'};//按层级关系提取address数
echo $json->{'content'}->{'address_detail'}->{'city_code'};
print_r($json);

$json输出:
stdClass Object ( [address] => CN|云南|昆明|None|CHINANET|0|0 [content] => stdClass Object ( [address] => 云南省昆明市 [address_detail] => stdClass Object ( [city] => 昆明市 [city_code] => 104 [district] => [province] => 云南省 [street] => [street_number] => ) [point] => stdClass Object ( [x] => 102.71460114 [y] => 25.04915310 ) ) [status] => 0 )

 

posted on 2018-01-30 16:09  黄聪  阅读(295)  评论(0编辑  收藏  举报