如果位置服务关闭,英特尔XDK地理定位将不会找到经纬度 [英] Intel XDK Geolocation won't find Lat/Long if location services off

查看:123
本文介绍了如果位置服务关闭,英特尔XDK地理定位将不会找到经纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用英特尔XDK开发一款应用程序,我正在使用Android(Nexus 6P)进行专门测试。

我添加了Cordova Geolocation插件以及谷歌定位服务为科尔多瓦和已经测试,我的位置服务打开,它正确地获得这两个插件的位置。

然而,当我关闭位置服务,什么都不显示



下面是我目前用来获取位置的代码:



document.addEventListener(deviceready,onDeviceReady,false); function onDeviceReady(){var Geo = {}; (navigator.geolocation){console.log('Started location'); console.log(cordova.plugins.locationServices.geolocation.getCurrentPosition(success,error)); //navigator.geolocation.getCurrentPosition(成功,错误,{enableHighAccuracy:true,maximumAge:Infinity,timeout:100000}); } //获取纬度和经度;函数成功(位置){console.log('SUCCESS location'); Geo.lat = position.coords.latitude; Geo.lng = position.coords.longitude; populateHeader(Geo.lat,Geo.lng); } function error(){console.log(Geocoder failed); }函数populateHeader(lat,lng){$('#Lat')。attr('data-lat',lat); $(#龙)ATTR(数据长,LNG); }}



要求用户切换位置数据,或者甚至更好的是获得用户的位置,而不需要位置服务。 解决方案

您说当我关闭位置服务时我假设您的意思是您已进入Android设置并禁用设备上的位置记录或关闭的共享位置。在这种情况下,您将不会获取任何数据,因为用户选择不共享该信息。请参阅自述文件中有关这两种插件的警告,这被认为是非常敏感的数据,因此,Android已赋予用户控制共享此信息的能力。



t知道是否有一个API可以明确告诉你该数据是否被用户禁用。无论如何,您应该报告您无法获取您需要的数据,这可能是由于各种原因造成的:


  • 位置数据已被用户禁用

  • 设备目前无法检索当前位置

  • 当前的位置模式不是允许检索一个位置


然后根据这个建议来修改或修改什么以允许这些数据被收集和使用。当然,如果用户没有兴趣与您的应用程序共享这些信息,您将不得不优雅地遵守。




编辑2017年2月23日:请参阅下面的评论以引用一些可帮助确定位置服务是否可用的插件。


I am using the Intel XDK to develop an app where i am specifically testing with android (Nexus 6P).

I have added the Cordova Geolocation plugin as well as Google Location Services for Cordova and have tested with my location services switched on and it correctly gets the position for both plugins.

However, when i switch off location services, nothing appears at all.

Here is the code i am currently using to get the location:

document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
    var Geo={};
    if (navigator.geolocation) {
        console.log('Started location');
        console.log(cordova.plugins.locationServices.geolocation.getCurrentPosition(success, error));
        //navigator.geolocation.getCurrentPosition(success, error, {enableHighAccuracy:true, maximumAge:Infinity, timeout:100000});
    }

    //Get the latitude and the longitude;
    function success(position) {
        console.log('SUCCESS location');
        Geo.lat = position.coords.latitude;
        Geo.lng = position.coords.longitude;
        populateHeader(Geo.lat, Geo.lng);
    }

    function error(){
        console.log("Geocoder failed");
    }

    function populateHeader(lat, lng){
        $('#Lat').attr('data-lat', lat);
        $('#Long').attr('data-long',lng);
    }
}

What i'm after, is either a way of asking the user to switch on location data, or even better would be to get the location of the user WITHOUT the location services being required.

解决方案

You say "when I switch off location services" I assume you mean that you have gone into the Android settings and disabled the "Location History" or the turned off sharing "Location" on the device. In this case, you won't get any data because the user has elected not to share that information. See the warnings in the README for both plugins, this is considered very sensitive data and, therefore, Android has given users the ability to control sharing this information.

I don't know if there is an API that would explicitly tell you whether or not that data has been disabled by the user. Regardless, you should probably report that you cannot get the data you need, which could be due to a variety of reasons:

  • the sharing of location data has been disabled by the user
  • the device is unable to retrieve a current position at this time
  • the current "location mode" is not allowing for retrieval of a position

And then follow that up with some advice on what to change or fix in order to allow that data to be collected and used. Of course, if the user is not interested in ever sharing that information with your app you'll have to gracefully comply.


EDIT 23 Feb 2017: See comment below for reference to some plugins that can help identify if location services are available.

这篇关于如果位置服务关闭,英特尔XDK地理定位将不会找到经纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆