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

Original 2019-04-16 15:17:56 303
abstract:public static function getUserCity($longitude, $latitude) {    $url = "https://apis.map.qq.com/ws/geocoder/v1/?location=" . $latitude&n
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];
}


Correcting teacher:查无此人Correction time:2019-04-16 15:36:13
Teacher's summary:完成的不错。请求第三方,都是使用curl方法,可以多练习,以后也可以用作采集数据。继续加油

Release Notes

Popular Entries