InvalidValueError: in property lat: not a number

Hi there !

I am trying to add a marker for user geolocation on a google map. I am getting this issue :

ERROR: InvalidValueError: in property lat: not a number

Here is my code :

this.geolocation.watchPosition().subscribe((position) => {

    console.log(position.coords.latitude);
    console.log(typeof(position.coords.latitude));
    
    let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
    
    let marker = new google.maps.Marker({
         map: this.map,
         position: new google.maps.LatLng(latLng)
       });

    });

The funny thing is the “console.log(typeof(position.coords.latitude));” return “Number” and “console.log(position.coords.latitude);” return a correct number format of my current latitude …

Any idea what I am doing wrong ?

Thank you ionic community!

1 Like

fixed !

I changed :

position: new google.maps.LatLng(latLng)

to :

position: latLng

Thank you very much to myself for helping me ! :smile:

1 Like

initMap(){
console.log(‘entre al initmap’);

    //here set center and latlng 
    let center = new google.maps.LatLng(4.71137832228122,-74.07196998596191);

    let mapOptions = {
      center: center,
      zoom: 11,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    this.map = new google.maps.Map(this.mapElement, mapOptions);

    this.marker = new google.maps.Marker({
      map: this.map,
      position: center ,  //here in marker set the center position
      label:"Punto de recojida",
      animation: google.maps.Animation.DROP,
      icon: './img/googlemaps/pin.png'
    });

}