Created
February 2, 2020 17:47
Ionic Capacitor Geolocation - Track user location
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Component, NgZone } from '@angular/core'; | |
import { Plugins } from '@capacitor/core'; | |
const { Geolocation } = Plugins; | |
@Component({ | |
selector: 'app-tab3', | |
templateUrl: 'tab3.page.html', | |
styleUrls: ['tab3.page.scss'] | |
}) | |
export class Tab3Page { | |
public lat: any; | |
public lng: any; | |
wait: any; | |
constructor(public ngZone: NgZone) { } | |
track() { | |
this.wait = Geolocation.watchPosition({}, (position, err) => { | |
this.ngZone.run(() => { | |
this.lat = position.coords.latitude; | |
this.lng = position.coords.longitude; | |
}) | |
}) | |
} | |
stopTracking() { | |
Geolocation.clearWatch({ id: this.wait }); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment