【问题标题】:To detect current geo location in mobile device检测移动设备中的当前地理位置
【发布时间】:2017-02-10 10:08:00
【问题描述】:

我使用下面的代码来检测 Angular 应用程序中的当前位置。这适用于所有桌面浏览器,但不适用于移动设备,请查找以下代码以获得更多理解。

if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(onPositionUpdate,locNotFound,{frequency:5000,maximumAge: 0, timeout: 100, enableHighAccuracy:true});
} else {
    // nothing 
}

function locNotFound () {
    console.log('location not found');
}
function onPositionUpdate(position) {
    var lat = position.coords.latitude;
    var lng = position.coords.longitude;
    var url = "https://maps.googleapis.com/maps/api/geocode/json?latlng=" + lat + "," + lng + "&sensor=true";
    $http.get(url)
        .then(function(result) {
            console.log(result);
        });
}

如您所见,在移动设备中调用了 locNotFound() 函数。它不应该这样做,因为 GPS 在移动设备上。

【问题讨论】:

  • 什么样的设备?
  • 我在 Android (chrome, mozilla) 和 iOS (safari) 中尝试过,但对我不起作用。

标签: javascript jquery angularjs geolocation gps


【解决方案1】:

我只能为您提供 Android 的部分答案。

请在 Android 上打开 Chrome 浏览器,单击右上角的图标(树点),单击设置,单击站点设置,然后检查位置设置。据我所知,默认情况下这是禁用的。

所以我认为您的问题与安全限制有关

问候

迈克尔

【讨论】:

  • 感谢迈克尔的意见。我试过了,但它仍然不适合我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-17
  • 1970-01-01
  • 2013-08-09
  • 1970-01-01
  • 1970-01-01
  • 2010-09-06
相关资源
最近更新 更多