简体   繁体   English

如何在没有互联网的情况下在uwp应用中获取经度和纬度?

[英]How to get latitude and longitude in uwp app without internet?

Hi i am using HP Tablet with GNSS sensor built-in with it , so i want to get Geo-location that is latitude and longitude without internet but i am not able to get Geo-location coordinates without internet in my UWP desktop app in win-10, below is my code snippet, Any Help would be Appreciated. 嗨,我正在使用内置有GNSS传感器的HP平板电脑,因此我想在没有互联网的情况下获取经纬度的地理位置,但是在Win UWP桌面应用程序中我无法在没有互联网的情况下获取地理位置坐标-10,下面是我的代码段,将不胜感激。

function getGeoposition() {
    var desiredAccuracyInMeters = 0;

    Windows.Devices.Geolocation.Geolocator.requestAccessAsync().done(
        function (accessStatus) {
            switch (accessStatus) {
                case Windows.Devices.Geolocation.GeolocationAccessStatus.allowed:

                    // If DesiredAccuracy or DesiredAccuracyInMeters are not set (or value is 0), DesiredAccuracy default is used.
                    var geolocator = new Windows.Devices.Geolocation.Geolocator();
                    geolocator.desiredAccuracyInMeters = desiredAccuracyInMeters;

                    getGeopositionPromise = geolocator.getGeopositionAsync();
                    getGeopositionPromise.done(
                        function (pos) {

                            WinJS.log && WinJS.log("Location updated", "sample", "status");

                        },
                        function (err) {

                            // i am getting error here saying "This operation returned because the timeout period expired."
                            WinJS.log && WinJS.log(err.message, "sample", "error");


                        }
                    );

                    WinJS.log && WinJS.log("Waiting for update...", "sample", "status");

                    break;

                case Windows.Devices.Geolocation.GeolocationAccessStatus.denied:
                    WinJS.log && WinJS.log("Access to location is denied.", "sample", "error");
                    break;

                case Windows.Devices.Geolocation.GeolocationAccessStatus.unspecified:
                    WinJS.log && WinJS.log("Unspecified error!", "sample", "error");
                    break;
            }
        },
        function (err) {
            WinJS.log && WinJS.log(err, "sample", "error");
        });
}

The GPS data acquisition is relevant to environment of the device or the Sensor, if there are much shelters, it is hard to get the location data, such as the high buildings. GPS数据采集与设备或传感器的环境有关,如果遮挡物较多,则很难获取位置数据,例如高楼大厦。 Please try to test the code on an open place to get the GPS data. 请尝试在空旷的地方测试代码以获取GPS数据。 Besides, you can use other device with GPS support to make sure you can get the GPS data. 此外,您可以使用其他具有GPS支持的设备来确保可以获取GPS数据。

On other way, as the document Guidelines for location-aware apps : 在其他方面,作为文档《位置感知应用指南》

To help conserve power, set the desiredAccuracy property to indicate to the location platform whether your app needs high-accuracy data. 为了帮助节省电量,请设置desiredAccuracy属性,以向位置平台指示您的应用程序是否需要高精度数据。 If no apps require high-accuracy data, the system can save power by not turning on GPS providers. 如果没有应用程序需要高精度数据,则系统可以通过不打开GPS提供程序来节省电量。

Set desiredAccuracy to HIGH to enable the GPS to acquire data. 将desireAccuracy设置为HIGH以使GPS能够获取数据。

Set desiredAccuracy to Default and use only a single-shot call pattern to minimize power consumption if your app uses location info solely for ad targeting. 如果您的应用仅将位置信息用于广告定位,则将desiredAccuracy设置为默认值,并且仅使用单次通话模式以最大程度地降低功耗。

You can try to set the desiredAccuracy to HIGH to enable the GPS to acquire data. 您可以尝试将desiredAccuracy设置为HIGH,以使GPS能够获取数据。

More detail, see the document Get the user's location and the official Geolocation sample. 有关更多详细信息,请参阅文档获取用户的位置和官方地理位置示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM