无法使用角度来推动工作

时间:2015-11-02 21:31:43

标签: javascript angularjs ionic pusher

我正在尝试使用推杆和角度一起反复击打api。有时它有效,有时它不起作用。我真的不确定为什么。

这是我的app.js和html。如果有人能够理解为什么它不会一直有效,那将是非常有用的!谢谢。



var exampleApp = angular.module('starter', ['ionic', 'pusher-angular'])

exampleApp.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
    // for form inputs)
    if(window.cordova && window.cordova.plugins.Keyboard) {
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
})


exampleApp.controller('MyCtrl', ['$scope', '$http', '$pusher', function($scope, $http, $pusher){
//d5e0d23678bdda79bd04
//fa15651bc1ad6c916fc7
  var client = new Pusher('d5e0d23678bdda79bd04');
  var pusher = $pusher(client);
  var issChannel = pusher.subscribe('iss-channel');

  // $scope.path = []

  // $http.get('/api/location').success(function(data){
  //   $scope.iss = data;
  // });

  issChannel.bind('new-location', function(data){
    console.log("Receiving event...")
    console.log(data);
    // $scope.iss = data
    // $scope.path.push([$scope.iss.iss_position.latitude, $scope.iss.iss_position.longitude])
  });


}]);
exampleApp.controller('MapController', function($scope, $ionicLoading) {
 
    google.maps.event.addDomListener(window, 'load', function() {
        var myLatlng = new google.maps.LatLng(37.3000, -120.4833);
 
        var mapOptions = {
            center: myLatlng,
            zoom: 16,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
 
        var map = new google.maps.Map(document.getElementById("map"), mapOptions);
 
        navigator.geolocation.getCurrentPosition(function(pos) {
            map.setCenter(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude));
            var myLocation = new google.maps.Marker({
                position: new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude),
                map: map,
                title: "My Location"
            });
        });
 
        $scope.map = map;
    });
 
});

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width">
        <title></title>
        <link href="lib/ionic/css/ionic.css" rel="stylesheet">
        <link href="css/style.css" rel="stylesheet">
        <script src="lib/ionic/js/ionic.bundle.js"></script>
        <!-- Jquery -->
        <script src="http://code.jquery.com/jquery-1.7.min.js"></script>
        <!-- AngularJS -->
       <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0-rc.0/angular.min.js"></script>
        
        <!-- pusher-js -->
        <script src="//js.pusher.com/3.0/pusher.min.js"></script>

        <!-- pusher-angular -->
        <script src="//cdn.jsdelivr.net/angular.pusher/latest/pusher-angular.min.js"></script>
        
        <script src="cordova.js"></script>
        <script src="js/app.js"></script>

        <!-- pusher for bower -->
      <!--  <script src="bower_components/dist/pusher.min.js"></script> -->
        <script>
        var pusher = new Pusher("d5e0d23678bdda79bd04");
        pusher.connection.bind('state_change', function() {
            $("#conn_status").text(pusher.connection.state);
        })
        </script>
    </head>
    <body ng-app="starter">
        <ion-pane>
            <ion-header-bar class="bar-stable">
                <h1 class="title">ISS TRACKER</h1>
            </ion-header-bar>
            
            <ion-content ng-controller="MapController">
                <div id="map" data-tap-disabled="true"></div>
                  
                <div ng-controller="MyCtrl">
                  latitude: {{ iss.iss_position.latitude }}<br>
                  longitude: {{ iss.iss_position.longitude }}
                 </div> 
                 <div>Connection status: <span id="conn_status"></span></div>
                 


            </ion-content>
            
        </ion-pane>
        <script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyASrLsi0TLN7GvfLzx0lX5rEwQfNzIj5gQ&sensor=true"></script>

    </body>
</html>
&#13;
&#13;
&#13;

0 个答案:

没有答案