navigator.geolocation.watchPosition fails on MacOS Monterey with google chrome

Issue

I’m writing an angular 14 application with chrome browser and MacOS Monterey and i’m trying to get the user current geo position on the browser using in order to display it with the @angular/google-maps api.

so in the component’s ngOnInit() I have the following code:

  ngOnInit(): void {
    navigator.geolocation.watchPosition((position) => {
      this.center = {
        lat: position.coords.latitude,
        lng: position.coords.longitude,
      }
    },function(positionError){
  alert('User not allowed - ' + positionError.message);
    },{timeout:10000})
  }

so the alert User not allowed - User defined Geolocation is displayed.

I tried to google and read on stackoverflow questions and i read that i must use ssl now.

so i run the development environment using ng serve --ssl, the browser asks for permission to get the current location but the results are the same, still the error alert is displayed.

what am I missing ?

Solution

I noticed that the browser had an icon that shows that location services is not enabled on my MacOS, i disabled and re-enabled it and now it works.

adding the permission api messes things up for me, having my regular code is enough for the user to allow permissions and then getting the location

Answered By – ufk

Answer Checked By – Gilberto Lyons (AngularFixing Admin)

Leave a Reply

Your email address will not be published.