I'm experiencing some difficulties with the geolocation
feature. It works fine when the user clicks allow, but there's an issue when using If else
. If the user clicks deny, it doesn't insert into the else
block. You can check out this DEMO for reference.
Component
ngOnInit() {
this.getUserLocation();
}
getUserLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(position => {
this.lat = position.coords.latitude;
this.lng = position.coords.longitude;
});
}else {
console.log("User has not allowed location access")
}
}