amazon-web-serviceshttpamazon-ec2httpsgoogle-geolocation

Calling geolocation api in http on AWS


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.


Solution

  • 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.