From de082bc9b1301b07f49c8b328d396c4b9e57399b Mon Sep 17 00:00:00 2001 From: wangxiaowei Date: Sun, 29 Sep 2024 14:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0try?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/controller/LocalStore.php | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/app/api/controller/LocalStore.php b/app/api/controller/LocalStore.php index 6e0d0a6d..d4241ecf 100755 --- a/app/api/controller/LocalStore.php +++ b/app/api/controller/LocalStore.php @@ -323,14 +323,16 @@ class LocalStore extends Api // 腾讯地图逆编码 public function getLocation() { - $post = $this->request->post(); - $url = 'https://apis.map.qq.com/ws/geocoder/v1?key=' . ConfigServer::get('map', 'tx_map_key') . '&address=' . $post['address']; - $result = file_get_contents($url); - $data = json_decode($result, true); - if ($data['message'] == 'Success') { - return JsonServer::success('', $data['result']['location']); + try { + $post = $this->request->post(); + $url = 'https://apis.map.qq.com/ws/geocoder/v1?key=' . ConfigServer::get('map', 'tx_map_key') . '&address=' . $post['address']; + $result = file_get_contents($url); + $data = json_decode($result, true); + if ($data['message'] == 'Success') { + return JsonServer::success('', $data['result']['location']); + } + } catch(\Exception $e) { + return JsonServer::error($e->getMessage()); } - - return JsonServer::error('地理位置获取失败'); } } \ No newline at end of file