0

我正在尝试获取用户的当前位置(在 genymotion 和实际的 android 设备中尝试过),但总是收到 {"nativeException":{}} 的错误。我正在启用 gps 对其进行测试,我的视图模型代码如下以访问该位置

var observable = require("data/observable");
var locationModule = require("location");
var LocationManager = new locationModule.LocationManager();


var enums = require('ui/enums');

var MainViewModel = (function (_super) {
    __extends(MainViewModel, _super);
    function MainViewModel() {
        _super.call(this);

    }

    MainViewModel.prototype.signIn = function () {
        //alert("Me");
        alert(JSON.stringify(LocationManager));
        alert(JSON.stringify(enums.Accuracy));
        var locationOptions = {
            desiredAccuracy: enums.Accuracy.high,
            updateDistance: 0,
            minimumUpdateTime: 5000,
            maximumAge: 20000
        };
        LocationManager.startLocationMonitoring(function (location) {
            console.log("Location received: " + location);
            alert(JSON.stringify(location));
        }, function (error) {
            alert("Location error received");
            alert(JSON.stringify(error));
        }, locationOptions);
    };

    return MainViewModel;
})(observable.Observable);
exports.MainViewModel = MainViewModel;
exports.mainViewModel = new MainViewModel();

这是我的 AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="org.nativescript.myapp"
    android:versionCode="1"
    android:versionName="1.0" >

   <supports-screens
        android:smallScreens="true"
        android:normalScreens="true"
        android:largeScreens="true"
        android:xlargeScreens="true"/>

   <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="22"/>

    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.INTERNET"/>
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

    <application
        android:name="com.tns.NativeScriptApplication"
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.tns.NativeScriptActivity"
            android:label="@string/title_activity_kimera"
            android:configChanges="keyboardHidden|orientation|screenSize">

             <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name="com.tns.ErrorReportActivity"/>
    </application>

</manifest>
4

1 回答 1

1

我敢打赌,您没有在AndroidManifest.xml(在 NativeScript 1.3.0: 中platforms/android/src/main)设置权限。

您希望有一条如下所示的行:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
于 2015-10-11T08:26:33.917 回答