Angular Nativescript:在线程内进行地理定位?
当我试图在工作线程上使用Geolocation inside时,程序会崩溃,并出现下一个错误Angular Nativescript:在线程内进行地理定位?,angular,typescript,geolocation,nativescript,Angular,Typescript,Geolocation,Nativescript,当我试图在工作线程上使用Geolocation inside时,程序会崩溃,并出现下一个错误 Error From Geolocation: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference JS: com.google.android.
Error From Geolocation: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String android.content.Context.getPackageName()' on a null object reference
JS: com.google.android.gms.common.GooglePlayServicesUtilLight.isGooglePlayServicesAvailable(Unknown Source)
JS: com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source)
JS: com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
JS: com.google.android.gms.common.GoogleApiAvailabilityLight.isGooglePlayServicesAvailable(Unknown Source)
JS: com.google.android.gms.common.GoogleApiAvailability.isGooglePlayServicesAvailable(Unknown Source)
JS: com.tns.Runtime.callJSMethodNative(Native Method)
JS: com.tns.Runtime.dispatchCallJSMethodNative(Runtime.java:1203)
JS: com.tns.Runtime.callJSMethodImpl(Runtime.java:1083)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1070)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1050)
JS: com.tns.Runtime.callJSMethod(Runtime.java:1042)
JS: com...
但当我从任何组件内部使用地理定位时,都不会发生这种情况,例如:
{
JS: "android": {},
JS: "latitude": 0,
JS: "longitude": 0,
JS: "altitude": 0,
JS: "horizontalAccuracy": 0,
JS: "verticalAccuracy": 0,
JS: "speed": 0,
JS: "direction": 0,
JS: "timestamp": "2019-12-20T16:40:47.000Z"
JS: }
这是我的线
// app/worker.ts
import "globals";
import * as Geolocation from 'nativescript-geolocation';
import { Accuracy } from "tns-core-modules/ui/enums";
const context: Worker = self as any;
context.onmessage = function(msg) {
Geolocation.getCurrentLocation({desiredAccuracy: 3, updateDistance: 10, maximumAge: 20000,timeout: 20000})
.then(function(loc) {
console.log(loc);
}, function(e){
console.log("Error From Geolocation: " + e.message);
});
};
我想知道是否存在在线程内使用地理位置的任何方法在访问worker上的位置之前,您是否从主线程获得了位置权限?是的,所有权限都已启用