// 一般都是 其他数据 入库成功 后 才 更新 经纬度的
//发起Http请求
$client = new Client(['timeout' => 5]);
//得到URL地址
$url = config('gaode.geocode');
$city = City::findOrFail($fangInfo->fang_city);
$url = sprintf($url, $fangInfo->fang_addr, $city->name);
//发起请求
$response = $client->get($url);
//可尝试 打印$response看看
$body = (string)$response->getBody();
$arr = json_decode($body, true);
//如果找到了经纬度,存入数据表
if (count($arr['geocodes']) > 0) {
$locationArr = explode(',', $arr['geocodes'][0]['location']);
$fangInfo->update([
'longitude' => $locationArr[0],
'latitude' => $locationArr[1]
]);
}