2016-07-28 102 views
0

我嘗試使用cordovaGeolocation獲取我的應用程序的當前位置,但未能獲取。 我的GPS是,但我不能讓當前的位置 以下是我的代碼使用cordovaGeolocation獲取當前位置

var posOptions = {timeout: 20000, enableHighAccuracy: false}; 
        $cordovaGeolocation 
         .getCurrentPosition(posOptions) 
         .then(function (position) { 

         lat = position.coords.latitude 
         long = position.coords.longitude 
        console.log("lat " + lat + " long " +long); 

        }, function(err) { 
         // error 

         console.log("error"); 
        }); 
        var watchOptions = {timeout : 20000, enableHighAccuracy: false}; 
        var watch = $cordovaGeolocation.watchPosition(watchOptions); 

        watch.then(
         null, 

        function(err) { 
        console.log(err) 
        }, 

        function(position) { 
        lat = position.coords.latitude 
        long = position.coords.longitude 
        console.log(lat + '' + long) 
       } 
       ); 

       watch.clearWatch(); 

我怎樣才能獲得當前位置?上面的代碼並沒有幫助我解決我的問題。 我沒有在我的設備獲取當前位置 請幫我解決這個問題

回答