guzzle 对接高德开放平台
// 一般都是 其他数据 入库成功 后 才 更新 经纬度的
//发起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] ]); }
版权声明:本文为zqblog1314原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。