I'm suing the plugin along with the directions plugin, here is the code below
private grantPermission(): Promise<boolean> {
return new Promise<boolean>((resolve, reject) => {
geolocation.enableLocationRequest()
.then((result) => {
resolve(true);
})
.catch((reason) => {
resolve(false);
})
});
}
public getCurrentLocation(): Promise<geolocation.Location> {
return new Promise<geolocation.Location>((resolve, reject) => {
geolocation.getCurrentLocation({
desiredAccuracy: Accuracy.high,
})
.then((result) => {
resolve(result);
})
.catch((reason) => {
reject(reason);
});
})
}
public getDirections(lng: string, lat: string) {
this.getCurrentLocation()
.then((result) => {
let directions: Directions = new Directions();
directions.available().then(avail => {
if (avail) {
directions.navigate({
from: { // optional, default 'current location'
lat: parseFloat(lat),
lng: parseFloat(lng)
},
to: [{
lat: result.latitude,
lng: result.longitude
}],
type: "driving", // optional, can be: driving, transit, bicycling or walking
ios: {
preferGoogleMaps: true, // If the Google Maps app is installed, use that one instead of Apple Maps, because it supports waypoints. Default true.
allowGoogleMapsWeb: true // If waypoints are passed in and Google Maps is not installed, you can either open Apple Maps and the first waypoint is used as the to-address (the rest is ignored), or you can open Google Maps on web so all waypoints are shown (set this property to true). Default false.
}
}).then(() => {
console.log("Maps app launched.");
}, error => {
console.log(error);
});
}
});
})
.catch((reason) => {
})
}
geolocation.getCurrentLocation goes into the catch with the following message
TypeError: Cannot read property 'GoogleApiAvailability' of undefined
at _isGooglePlayServicesAvailable (geolocation.js:225)
at geolocation.js:210
at new ZoneAwarePromise (zone-nativescript.js:902)
at _makeGooglePlayServicesAvailable (geolocation.js:209)
at geolocation.js:179
at ZoneDelegate.invoke (zone-nativescript.js:388)
at Object.onInvoke (core.umd.js:16201)
at ZoneDelegate.invoke (zone-nativescript.js:387)
at Zone.run (zone-nativescript.js:138)
at zone-nativescript.js:883
at ZoneDelegate.invokeTask (zone-nativescript.js:421)
at Object.onInvokeTask (core.umd.js:16192)
at ZoneDelegate.invokeTask (zone-nativescript.js:420)
at Zone.runTask (zone-nativescript.js:188)
at drainMicroTaskQueue (zone-nativescript.js:595)
Platform: Android Type: Device - Huawei P10
Please, provide the following version numbers that your issue occurs with:
I have went through the documentation step by step, i have added google play services in app.gradle
I'm suing the plugin along with the directions plugin, here is the code below
geolocation.getCurrentLocation
goes into the catch with the following message