1

科爾多瓦地理位置插件只能使用手機的GPS位置。如果手機GPS沒有鎖定(例如在建築物內),則應該採用COARSE_LOCATION即WIFI或蜂窩塔。科爾多瓦地理位置插件問題

我通過僅提供ACCESS_COARSE_LOCATION的權限並註釋掉ACCESS_FINE_LOCATION的代碼來檢查它。在這種情況下,我們得到錯誤代碼:3(超時)。

$scope.showpopup=function(status){ 
       console.log("show pop up function called"); 
       var cont; 
       switch (status) { 
        case 1: 
         cont = "User denied the request for Geolocation." 
         break; 
        case 2: 
         cont = "Location information is unavailable." 

         break; 
        case 3: 
         cont = "The request to get user location timed out." 
         break; 
        default: 
         cont = "An unknown error occurred." 
         break; 
       } 
       $ionicPopup.alert({ 
        title: 'Gps error', 
        content: cont 
       }); 
     }; 


navigator.geolocation.getCurrentPosition(
    function(position){ 
     //Variables to use for showing latitude and longitude by position.coords . 
    },function(error){ 
     $scope.showpopup(error.code); 
     },{timeout:10000,maximumAge:60000,enableHighAccuracy:true}); 

回答

1

你必須enableHighAccuracy設置爲真正,這表明你想要GPS。將其更改爲false,然後您就可以獲得基於網絡(wifi或蜂窩)的位置。

有關詳細信息,請參閱:

https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/

+0

感謝@Neil克雷斯韋爾我們會嘗試。 – Abhishek

+0

對不起,我會發現它非常有趣,不要讓我錯在這裏,我必須糾正你,@尼爾克雷斯韋爾,但這不是真的。該插件基於[html5地理位置API](https://dev.w3.org/geo/api/spec-source.html),它告訴「enableHighAccuracy屬性提供應用程序希望獲得最佳效果的提示可能的結果「,所以你告訴api你想使用gps/glonass/galileo/beidou,但不能保證coords是來自這些衛星geotechs,所以這個api也可以在不太精確的技術如wifi上回退/ GSM。 – Blauharley

+0

正如所參考的句子所述:如果應用程序在具體情況下可能會使用高精度技術,那麼它將使用高精度技術,否則將自動使用不太精確的技術,如果這些技術現在可以使用的話。它也可以閱讀[這裏](http://stackoverflow.com/questions/15310742/if-i-have-access-fine-location-already-can-i-omit-access-coarse-location)當enableHighAccuracy是設置爲true,可以使用高精度技術和不太精確的技術,andriod可以使用哪種技術取決於當前的位置。 – Blauharley

相關問題