对接百度地图API 实现地址转经纬度
<?php class BaiduLBS { public static $_ak = '你的KEY值'; # Util::request 是我封装的一个请求URL类,自己可以写一个 可以提交 post,get的请求类,或者再下面写俩个 一个post 一个get请求 这都随意。网上一搜一大把 //获取经纬度坐标 public static function getLocation($data) { if (!isset($data['address'])) { $info = $data; $url = 'http://api.map.baidu.com/geocoder/v2/'; $info['ak'] = BaiduLBS::$_ak; $info['output'] = 'json';//输出格式
$lbs_result = Util::request($url, 'POST', $info, false, 30); }else { $address = $data['address']; $ak = BaiduLBS::$_ak;; $url = 'http://api.map.baidu.com/geocoder/v2/?address=' . $address . '&output=json&ak=' . $ak;
$lbs_result = Util::request($url, 'GET', '', false, 30); } return $lbs_result; } }
$data = array(); $data['address'] = $receiver_address; $baiduBS = new BaiduLBS(); $baiduBSInfo = $baiduBS::getLocation($data); $baiduBSInfoArr = json_decode($baiduBSInfo, true); $receive['user_lng'] = $baiduBSInfoArr['result']['location']['lng']; # 用户经度 $receive['user_lat'] = $baiduBSInfoArr['result']['location']['lat'];
作者地址:https://www.cnblogs.com/G921123/
创作也有乐趣 知识分享 转载注明出处 相互理解 谢谢!
创作也有乐趣 知识分享 转载注明出处 相互理解 谢谢!