2017-02-10 76 views
0

我已经使用下面的代码来检测角度应用中的当前位置。这与所有的桌面浏览器都能正常工作,但它不适用于移动设备,请在下面的代码中找到更多的理解。检测移动设备中当前的地理位置

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在移动设备上。

+0

什么样的设备? –

+0

我在Android(chrome,mozilla)和iOS(safari)中尝试过不适合我。 –

回答

0

我只是可以给你一个Android的部分答案。

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

所以我觉得你的问题是关系到安全限制

问候

迈克尔

+0

感谢迈克尔的输入。我试过这个,但它仍然不适合我。 –