//根据浏览器ip获取经纬度 要求注册一个百度地图开发账号 要用到key 就是下边的ak
//获取客户端ip地址
header("content-type:text/html;charset=utf-8");
$get_ip = $_SERVER['REMOTE_ADDR'];
/*echo "ip:".$get_ip;*/
if ($get_ip=='127.0.0.1') {//如果获取到的ip为127.0.0.1 会报错 在这随便给一个ip
$get_ip='58.30.228.35';
}
//根据百度地图
//coor 参数必须有 这个代表 要获取百度地图上的经纬度
$content = file_get_contents("http://api.map.baidu.com/location/ip?ak=Gi1nULBk8PY6PdBVyqnrT8Aguht5L639&ip={$get_ip}&coor=bd09ll");
$json = json_decode($content, true);
print_r($json);
/*输出数组 Array ( [address] => CN|北京|北京|None|BGCTVNET|0|0 [content] => Array ( [address] => 北京市 [address_detail] => Array ( [city] => 北京市 [city_code] => 131 [district] => [province] => 北京市 [street] => [street_number] => ) [point] => Array ( [x] => 116.40387397 [y] => 39.91488908 ) ) [status] => 0 )*/
echo 'log:',$json['content']['point']['x'];//按层级关系提取经度数据 log:116.40387397
echo '<br/>';
echo 'lat:',$json['content']['point']['y'];//按层级关系提取纬度数据 lat:39.91488908