``` ~~~ public function test(){ $address='地址'; //地址 $city='四川成都'; // 城市 $result =[]; $ak = 'XXXXXXXXXXXXXXXXXX';//您的百度地图ak,需要服务器类型的 $url ="http://api.map.baidu.com/geocoder/v2/?callback=renderOption&output=json&address=".$address."&city=".$city."&ak=".$ak; $data = file_get_contents($url); $data = str_replace('renderOption&&renderOption(', '', $data); $data = str_replace(')', '', $data); $data = json_decode($data,true); if (!empty($data) && $data['status'] == 0) { $result['longitude'] = $data['result']['location']['lng']; // 经度 $result['latitude'] = $data['result']['location']['lat']; // 纬度 return json($result);//返回经纬度结果 }else{ return json(['error']); } } ~~~ ``` ## **返回内容** ``` { "longitude": 104.03505599181334, "latitude": 30.627139858922366 } ```