PHP根据地址获取经纬度(百度地图 )
/** * [getLoLa description] * @Author:XuXianGang * @Method: 根据地址获取经纬度 * @DateTime:2023-02-06T16:01:45+0800 * @param [type] $address [description] * @return [type] [description] */ function getLoLa($address) { $ak=""; $baiduAK = 'https://api.map.baidu.com/geocoding/v3/?address=' . $address . '&city='.$city.'&output=json&ak='.$ak.'&callback=showLocation'; $lola = file_get_contents($baiduAK); $data = str_replace('showLocation&&showLocation(', '', $lola); $data = str_replace(')', '', $data); $data = json_decode($data,true); if (!empty($data) && $data['status'] == 0) { $result[] = $data['result']['location']['lng']; $result[] = $data['result']['location']['lat']; return implode(",",$result); //返回经纬度结果 }else{ return null; } }
getLoLa("河南省郑州市管城回族区紫荆山路56号华林新时代广场")