@Sweg wrote:
am trying to load Google Maps into my Ionic app, & center the map on my current coordaintes using Geolocation.
Below I am retrieving the long & lat of my current location, & assigning the values to local variables:
constructor(private afAuth: AngularFireAuth, private afs: AngularFirestore) { this.anonLogin(); } anonLogin() { this.afAuth.auth.signInAnonymously().then(res => { this.user = res.user; this.isTracking = true; this.watch = Geolocation.watchPosition({}, (position, err) => { if (position) { this.lat = position.coords.latitude; this.lng = position.coords.longitude; } }); }); }
And here is where I’m creating the map:
ionViewWillEnter() { this.loadMap(); } loadMap() { let latLng = new google.maps.LatLng(this.lng, this.lat); let mapOptions = { center: latLng, zoom: 5, mapTypeId: google.maps.MapTypeId.ROADMAP }; this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions); }
In
loadMap()
.this.lng
&this.lat
are null. But inanonLogin()
, they’re the correct values.How can I center my map on these co-ordinates when the app / map loads?
Posts: 1
Participants: 1