Cordova Angularjs地理定位和重定向无法正常工作

时间:2014-10-22 19:33:34

标签: angularjs cordova geolocation

我正在使用cordova.geolocation,如果启用了位置服务,我正在尝试重定向到下一页。但不幸的是,它不起作用。这就是我的控制器的样子

myApp.controller('checkLocation', ['$scope','$location','cordova','SessionService',function($scope,$location, cordova,SessionService) {
    function startRedirecting(){
        $location.path('/login');
    }
    function onSuccess(position) {
       /* alert('Latitude: '          + position.coords.latitude          + '\n' +
            'Longitude: '         + position.coords.longitude         + '\n' +
            'Altitude: '          + position.coords.altitude          + '\n' +
            'Accuracy: '          + position.coords.accuracy          + '\n' +
            'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
            'Heading: '           + position.coords.heading           + '\n' +
            'Speed: '             + position.coords.speed             + '\n' +
            'Timestamp: '         + position.timestamp                + '\n');

        */
        SessionService.set('current_user_longitude',position.coords.longitude);
        alert(SessionService.get('current_user_longitude'));
        startRedirecting();
    };

// onError Callback receives a PositionError object
//
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
            'message: ' + error.message + '\n');
    }


    cordova.ready.then(function(){

       // $location.path('/login');<--THIS WORKS
        if (!checkConnection()){
            navigator.app.exitApp();
        }
        else{
            navigator.geolocation.getCurrentPosition(onSuccess, onError);
        }


        //checkConnection();
        /*var div = document.getElementById("map_canvas");
        map = plugin.google.maps.Map.getMap(div);
*/
    });
}]);

任何建议

0 个答案:

没有答案