http_build_query([ 'address' => $address, ]), 'headers' => [ 'Content-Type' => 'application/x-www-form-urlencoded', 'Authorization' => 'APPCODE ' . $appcode, ], ]); if ($res->getStatusCode() != 200) { throw new \Exception('Error: ' . $res->getStatusCode() . ' ' . $res->getReasonPhrase()); } $data = json_decode((string)$res->getBody(), true); if ($data['code'] == 200) { return [ 'lng' => $data['data']['location']['lng'], 'lat' => $data['data']['location']['lat'], ]; } throw new \Exception('Error: ' . $data['code'] . ' ' . $data['msg']); } catch (\Throwable $e) { return [ 'lng' => 0, 'lat' => 0, ]; } } }