This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Repository navigation
This repository was archived by the owner on Nov 8, 2023. It is now read-only.
Methods watchLocation / getCurrentLocation hangs #248
Copy link
Copy link
Open
Labels
Description
Which platform(s) does your issue occur on?
- Android (I'm not developing for iOS)
- Android 9
- Device Moto G 2014 (Thea) / Emulator Google Pixel 3 (Genymotion)
Please, provide the following version numbers that your issue occurs with:
- CLI: 6.1.2
- Cross-platform modules: 6.1.1
- Runtime(s): 6.1.1
- Plugin(s):
"dependencies": {
"@nstudio/nativescript-checkbox": "^1.0.0",
"@nstudio/nativescript-floatingactionbutton": "^1.1.0",
"@nstudio/nativescript-loading-indicator": "^1.0.0",
"@vue/devtools": "^5.1.1",
"axios": "^0.19.0",
"moment": "^2.24.0",
"nativescript-contacts": "^1.6.2",
"nativescript-drop-down": "^5.0.4",
"nativescript-geolocation": "^5.1.0",
"nativescript-google-maps-sdk": "^2.8.1",
"nativescript-masked-text-field": "^4.0.3",
"nativescript-permissions": "^1.3.8",
"nativescript-socketio": "^3.3.1",
"nativescript-theme-core": "~1.0.6",
"nativescript-toast": "^2.0.0",
"nativescript-toasty": "^2.0.1",
"nativescript-ui-dataform": "^5.1.1",
"nativescript-ui-sidedrawer": "^7.0.2",
"nativescript-vue": "~2.4.0",
"nativescript-vue-devtools": "^1.2.0",
"net": "^1.0.2",
"tns-core-modules": "^6.1.1",
"vue-i18n": "^8.14.1",
"vuex": "^3.1.1"
},
"devDependencies": {
"@babel/core": "~7.6.4",
"@babel/preset-env": "~7.6.3",
"babel-loader": "~8.0.6",
"nativescript-dev-webpack": "^1.2.1",
"nativescript-vue-template-compiler": "~2.4.0",
"node-sass": "^4.12.0",
"vue-loader": "~15.7.1"
}Please, tell us how to recreate the issue in as much detail as possible.
I'm using Google Maps SDK and Geolocation, so when mapReady event is triggered, I call a method named startTracking which enable and checks for location permissions, and then calls a method named watchLocation, which will use watchLocation method from nativescript-geolocation. watchLocation does return the watch ID, but it hangs, nothing happens, it does not enter in success callback nor in error callback. I tried before with getCurrentLocation using async/await and the same thing happens, nothing happens and it does not execute the code after this method call.
Is there any code involved?
mapReady:
async mapReady (args) {
try {
// Get map view
this.mapView = args.object
// Set map settings
this.mapView.settings.mapToolbarEnabled = false
this.mapView.setStyle([
{
featureType: 'poi',
stylers: [{ visibility: 'off' }]
}
])
// Start tracking
await this.startTracking()
} catch (ex) {
console.log(ex)
alert(ErrorFormatter(ex))
}
},startTracking:
async startTracking () {
try {
// Ask for location permission
await geolocation.enableLocationRequest(true, true)
// Check if location is enabled
const isEnabled = await geolocation.isEnabled()
// If location is enabled
if (isEnabled) {
// Start location watch
this.watchLocation()
}
} catch (ex) {
console.log(ex)
alert(ErrorFormatter(ex))
}
},watchLocation:
watchLocation () {
try {
this.watchId = geolocation.watchLocation(
loc => {
if (loc) {
this.map.latitude = loc.latitude
this.map.longitude = loc.longitude
}
},
e => {
console.log(e)
alert(ErrorFormatter(e))
},
{
desiredAccuracy: Accuracy.HIGH,
updateDistance: 1,
updateTime: 3000,
minimumUpdateTime: 100
}
)
} catch (ex) {
console.log(ex)
alert(ErrorFormatter(ex))
}
},Reacted by William Ma
Activity
andresilva-cc commentedon Oct 13, 2019
After a while I got:
[Error: Timeout while searching for location!]tbozhikov commentedon Nov 1, 2019
Hi @DeehSlash, the timeout error you have comes from the
getCurrentLocation()API of the plugin rather thanwatchLocation(). So, could this timeout be unrelated to the code (usingwatchLocation()) you have pasted in your initial post?Having the provided info, to me it looks that a hang in your app could be caused by some code like:
Such a call would hang the app either until the location is acquired, or until the timeout is reached. Refer to the code in Android implementation. So, if you use it this way, maybe you should reconsider that.
If that is not your case, a sample app reproducing the issue would be best to be able to assist you further.
Hope this helps.