
安装插件
composer require guzzlehttp/guzzle
引入类
use GuzzleHttp\Client;
// 获取地址经纬度 引入的请求类
$client = new Client(['timeout' => 10]);
// 得到请求地址
$url = config('map.gaoCode');
$url = sprintf($url, $housingData['fang_addr']);
$response = $client->get($url);
$bode = (string)$response->getBody();
$arr = json_decode($bode, true);
// 经纬度存表
if (count($arr['geocodes']) > 0) {
$locationArr = explode(',', $arr['geocodes'][0]['location']);
$housingData['longitude'] = $locationArr[0];
$housingData['latitude'] = $locationArr[1];
}
最后添加到要引入的字段名
本文介绍了如何使用GuzzleHttp库从配置的高德地图API获取房源地址的经纬度,通过实例展示了如何构造请求、解析响应并存储坐标信息。
1137

被折叠的 条评论
为什么被折叠?



