Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70435

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

$
0
0

@JordanoBaluz wrote:

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);
}

Posts: 3

Participants: 2

Read full topic


Viewing all articles
Browse latest Browse all 70435

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>