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.
CodePudding user response:
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.
CodePudding user response:
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.