Issue
I'm stuck at geolocation
. Actually it working fine but some problem appear when I using If else
. When User click allow location it working but the problem appear when user click not allow, it not insert in else
. This DEMO as 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 not allow")
}
}
Solution
@shayan ans is the correct approach to get your desire result. I will modify his approach a little bit to meet your expectations.
Try something like this
navigator.geolocation.getCurrentPosition(function(){
alert('Location accessed')
},function(){
alert('User not allowed')
},{timeout:10000})
Answered By - Jaydip Jadhav
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.