I have an Ionic 5 / Capacitor app and I'm using geolocation.
Here is the code:
import { Component } from '@angular/core';
import { Geolocation } from '@capacitor/core';
@Component({
selector: 'app-tab1',
templateUrl: 'tab1.page.html',
styleUrls: ['tab1.page.scss']
})
export class Tab1Page {
latitude: number;
longitude: number;
constructor() {
this.getLocation();
}
async getLocation() {
const position = await Geolocation.getCurrentPosition({ enableHighAccuracy: true, timeout: 5000, maximumAge: 0 });
this.latitude = position.coords.latitude;
this.longitude = position.coords.longitude;
}
}
When I run it on my browser this.latitude and this.longitude shows results but when I run it on Android Studio either the emulator or the phone it shows no results at all.
How can I fix this issue as it's giving me no errors, it's just not returning any gps coordinates on my Android phone or emulator.