/** * wgs84 转百度地图坐标 * @param $lng * @param $lat * @return array */ function toBaiduLocation($lng,$lat){ $ak = 'nljzQ7WZULfz4GXA6biVFlbkGwvQvueN'; $url = 'https://api.map.baidu.com/geoconv/v1/?coords='.$lng.','.$lat.'&from=1&to=5&ak='.$ak; $result = httpGet($url); $json = json_decode($result,true); if($json['status'] == 0 && isset($json['result'][0])){ $res = $json['result'][0]; return ['lng'=>$res['x'],'lat'=>$res['y']]; } return ['lng'=>$lng,'lat'=>$lat]; } function httpGet($url) { $curl = curl_init(); curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, to true); curl_setopt ($ curl, CURLOPT_TIMEOUT, 500); // To ensure the security of data transmission between the server and the third party server WeChat, all micro-channel interface using https call mode, the following two lines of code must be used to open ssl security verification. // code here if validation fails during deployment, please go http://curl.haxx.se/ca/cacert.pem download a new certificate identification documents. curl_setopt ($ curl, CURLOPT_SSL_VERIFYPEER, to true); curl_setopt ($ curl, CURLOPT_SSL_VERIFYHOST, to false); curl_setopt ($ curl, CURLOPT_URL to, $ URL); $ RES = the curl_exec ($ curl); curl_close ($ curl); return $ RES; } $ toBaiduLocation RES = (102.7449617,24.983720); print_r ($ RES);
1, using the interface conversion Baidu
Baidu document http://lbsyun.baidu.com/index.php?title=webapi/guide/changeposition
ak own open application platform in Baidu
http://lbsyun.baidu.com/apiconsole/key