2016-07-28 100 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(); 

我怎样才能获得当前位置?上面的代码并没有帮助我解决我的问题。 我没有在我的设备获取当前位置 请帮我解决这个问题

回答