在AWS上调用HTTP中的地理位置API

发布于 2025-02-10 15:33:02 字数 1219 浏览 0 评论 0原文

我正在尝试构建一个需要用户当前位置的应用程序,并且我在以下位置获得了该应用程序,

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和HTTP?如果是这样,我该如何绕过它允许HTTP调用HTML5地理位置API?这只是一个个人安全项目,这不是问题。我没有能力购买域并从那里获得SSL证书。

I am trying to build a app that requires a users current location and I acquire that with the following

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.");
    }     
};

It works fine on localhost but when I host it on AWS EC2 it does now give the popup to open location service but directly goes to "User denied the request for Geolocation.". Am I correct in understanding that this is because of http and https? If so how do I bypass this to allow http to call the html5 geolocation api? This is just a personal project to security is not an issue. I do not have the ability to buy a domain and get a SSL certificate from there.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谁把谁当真 2025-02-17 15:33:02

您的EC2实例需要Internet连接才能达到API服务。请检查您已在子网中托管的,可以通过或NAT到达Internet。还可以正确设置SG或NACL以进入Internet。您可以通过在实例中访问Google.com来快速执行此操作。

Your EC2 instance need internet connectivity to reach the API service. Please check you have hosted in a subnet from where you can reach internet either via the or nat. Also check you sg or nacl is setup correctly to reach the internet. You can do this quickly by accessing google.com inside instance.

轻拂→两袖风尘 2025-02-17 15:33:02

我发现这是HTTP,HTTPS的东西。我使用GitHub学生开发人员包进行了注册,并将其用于设置SSL,它的工作方式就像魅力。

I found that it is a http, https thing. I registered a domain using github student developer pack and used that to setup ssl and it worked like a charm.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文