API Maps "setCenter: not a LatLng" - Ionic-v4

I’m trying to get the location via geolocation and center the map, but i receive the error “not a LatLng”, someone know why?

export class HomePage{

  constructor (private geolocation:Geolocation,
    ){}
    
    ngOnInit(){
      initMap(this.getLocation);
      this.getLocation();
    }
    
    getLocation(){
      var rta: LatLng;
      rta = this.geolocation.getCurrentPosition();
      console.log('rta: ', rta);
      return rta;
    }    
}

function initMap(position) {
  const myLatLng = position;
  console.log('posicao: ', myLatLng);
  var map = new google.maps.Map(document.getElementById('map'), {
    zoom: 16,
    center: myLatLng
  });
  
  map.addListener('click', function(e) {
    placeMarkerAndPanTo(e.latLng, map);
  });
}

function placeMarkerAndPanTo(latLng, map) {
  var marker = new google.maps.Marker({
    position: latLng,
    map: map
  });
  map.panTo(latLng);
}

I’d start by removing the function keyword from the methods in your class.

Also maybe post the error that’s logged. When is the error being thrown?

Actually the function are out of the class, the image below show the error:

my idea it’s catch the coords and pass through parameters to the function initMap, it’s this possible?