返回根据经纬度获取......登陆

根据经纬度获取用户所在城市

League2019-04-16 15:17:56302
public static function getUserCity($longitude, $latitude)
{
   $url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" . $latitude . ',' . $longitude . "&key=XXXXXXXXXXXX";
   $res = CurlService::curlGet($url);
   $res['data'] = json_decode($res['data'], true);
   if ($res === false) {
      throw new \Exception('api请求失败', '3');
   }
   if ($res['data']['status'] !== 0) {
      throw new \Exception($res['data']['message'], '3');
   }
   $provinceName = $res['data']['result']['address_component']['province'];
   $cityName = $res['data']['result']['address_component']['city'];
   return ['province_name' => $provinceName, 'city_name' => $cityName];
}


最新手记推荐

• 用composer安装thinkphp框架的步骤• 省市区接口说明• 用thinkphp,后台新增栏目• 管理员添加编辑删除• 管理员添加编辑删除

全部回复(0)我要回复

暂无评论~
  • 取消回复发送