私は以下のコードを使って角型アプリの現在の位置を検出しました。これはすべてのデスクトップブラウザで問題なく動作していますが、モバイルデバイスでは動作しません。モバイルデバイスの現在の地理的位置を検出するには
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)がうまくいきませんでした。 –