我正在嘗試構建一個需要用戶當前位置的應用程式,我通過以下方式獲取該應用程式
const showError = (error) => {
switch(error.code) {
case error.PERMISSION_DENIED:
setErrorToast("User denied the request for Geolocation.");
setLoc({ lng: 77.5946, lat: 12.9716 });
break;
case error.POSITION_UNAVAILABLE:
setErrorToast("Location information is unavailable.");
setLoc({ lng: 77.5946, lat: 12.9716 });
break;
case error.TIMEOUT:
setErrorToast("The request to get user location timed out.");
setLoc({ lng: 77.5946, lat: 12.9716 });
break;
case error.UNKNOWN_ERROR:
setErrorToast("An unknown error occurred.");
setLoc({ lng: 77.5946, lat: 12.9716 });
break;
}
setIsLoading(false);
};
const getCurLoc = () => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(setMapInitLoc, showError);
}
else {
console.log("Geolocation is not supported by this browser.");
}
};
它在 localhost 上運行良好,但是當我將它托管在 AWS EC2 上時,它現在確實提供了打開位置服務的彈出視窗,但直接轉到“用戶拒絕地理定位請求。”。我是否正確理解這是因為 http 和 https?如果是這樣,我該如何繞過它以允許 http 呼叫 html5 地理定位 api?這只是個人專案,安全不是問題。我沒有能力購買域并從那里獲得 SSL 證書。
uj5u.com熱心網友回復:
您的 EC2 實體需要 Internet 連接才能訪問 API 服務。請檢查您是否托管在可以通過 nat 或 nat 訪問 Internet 的子網中。還要檢查您的 sg 或 nacl 是否設定正確以訪問互聯網。您可以通過訪問 google.com 內部實體來快速完成此操作。
uj5u.com熱心網友回復:
我發現它是一個http,https的東西。我使用 github student developer pack 注冊了一個域,并用它來設定 ssl,它就像一個魅力。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/498120.html
標籤:亚马逊网络服务 http 亚马逊-ec2 https 谷歌地理定位
上一篇:從領英請求資料
