安装插件
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];
}
最后添加到要引入的字段名