Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
5.0k views
in Technique[技术] by (71.8m points)

Ionic Capacitor Geolocation, how to ask for permission

i'm using ionic capacitor and want to receive GPS coordinates using the Geolocator plugin. The problem is that my app is never asking for permission therefore i cannot receive any coordinates. Here is my code:

getLocation(): void{
this.geolocation.getCurrentPosition().then((resp) => {
  // resp.coords.latitude
  // resp.coords.longitude
}).catch((error) => {
  console.log('Error getting location', error);
});

let watch = this.geolocation.watchPosition();
watch.subscribe((data) => {
  if ("coords" in data) {
    this.lng = data.coords.longitude;
    this.lat = data.coords.latitude;
    this.getLocations();
  }else{
    this.snackBar.open("Kein Zugriff auf GPS Koordinaten", "Ok", {
      duration: 2000,
    });
  }
  console.log(this.lat, this.lng);
});
}

and here is my info.plist file: info.plis


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...