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方法,可以多練習(xí),以后也可以用作采集數(shù)據(jù)。繼續(xù)加油