Open mrwrighty opened 3 years ago
import * as gps from '@nativescript-community/gps'
this.gps = new gps.GPS()
Thats TypeScript not Javascript isn't it. I need Javascript
it is es6 so it is JavaScript
Getting this error though NativeScript encountered a fatal error: Uncaught TypeError: Cannot set property 'gps' of undefined
Code is as above
import * as gps from '@nativescript-community/gps'
this.gps = new gps.GPS()
@mrwrighty that s normal. this is not defined at top level! you need to integrate that correctly in your app.
Sorry I'm at a complete loss here, I've never used "import" but "require" in all my code as mentioned in my OP. The code is at the top of my page.js file as used previously as as I did with nativescript-geolocation as in:-
var geolocation = require("nativescript-geolocation");
the issue is with this
. it is intended to be used in a class object. use a var instead
I have modified your code directly as follows:
var gps_master = require("@nativescript-community/gps");
var gps = new gps_master.GPS();
Many thanks, I'm now getting GPS locations.
Need to integrate for background use irrespective of app state which I understand this plugin will do. Will work on it and come back if I run in to issues. Only considering iOS at the moment.
Many thanks, I'm now getting GPS locations.
Need to integrate for background use irrespective of app state which I understand this plugin will do. Will work on it and come back if I run in to issues. Only considering iOS at the moment.
Background locations for iOS will work as long as the app is not force closed. For Android this will not work out-of-the-box, foreground service needs to be written to get the same background locations when app is minimized.
@mrwrighty indeed as @sivo1981 you need special handling both on iOS and Android:
I previously used nativescript-background-geolocation-lt but support for Nativescript has been withdrawn which is extremely frustrating. There is no reference on the @nativescript-community/gps plugin about background tasks, battery that sort of thing. I'm guessing its a longways off the one I used to use, but I have no options now.
Below is the description of the old plugin I used.
_The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
The plugin's Philosophy of Operation is to use motion-detection APIs (using accelerometer, gyroscope and magnetometer) to detect when the device is moving and stationary.
When the device is detected to be moving, the plugin will automatically start recording a location according to the configured distanceFilter (meters).
When the device is detected be stationary, the plugin will automatically turn off location-services to conserve energy._
I am migrating a project to NS7+ that had broken plugins that did not support NS7. I've moved from nativescript-geolocation to @nativescript-community/gps
I'm trying to translate the TS example in to JS, I've not made the move to TS as my app is written in JS and annoyed that all examples tend to use TypeScript rather than JavaScript and the documentation is non existent.
Im setting up GPS using the following:
var gps_master = require("@nativescript-community/gps"); var gps = new gps_master();
But get an error
NativeScript encountered a fatal error: Uncaught TypeError: gps_master is not a constructor
How do I declare GPS and get location values in Javascript to pass to ui-mapbox