Javascript事件监听器无法正常工作

时间:2014-11-18 16:59:33

标签: javascript android cordova

当我包含设备就绪监听器时,我的地图永远不会加载(图像捕获永远不会起作用,但这是一个不同的问题......)。如果没有设备就绪监听器,地图就可以正常工作。

任何建议都将不胜感激!!

P.S。我正在压缩文件,把它放在phonegap上并在我的moto x上运行。

<body onload="onLoad()">
  <div data-role="page" data-control-title="Home" id="page1">
  <div data-theme="a" data-role="header" data-position="fixed">
      <h3>
          Campus Kitchen
      </h3>
  </div>
  <div data-role="content">
      <div id="map">
        <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css" />
        <script src="http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.js"></script>
        <script type="text/javascript">
        function onLoad(){
          document.addEventListener("deviceready", onDeviceReady, false);
        }

        function onDeviceReady(){
          var map = L.map('map');

          L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png').addTo(map)

          map.locate({setView: true, maxZoom: 16});

          function onLocationFound(e) {
            var radius = e.accuracy / 2;

            L.marker(e.latlng).addTo(map).bindPopup("Your pickup spot is in this area").openPopup();
            L.circle(e.latlng, radius).addTo(map);
          }

          map.on('locationfound', onLocationFound);

          function onLocationError(e) {
            alert(e.message);
          }

          map.on('locationerror', onLocationError);

          function onPhotoDataSuccess(imageData){
            var smallImage = document.getElementById('smallImage');
            smallImage.style.display = "block";
            smallImage.src = "data:image/jpeg;base64," + imageData;
          }

          function capturePhoto(){
            navigator.camera.getPicture(onPhotoDataSuccess, onFail, {quality: 50, destinationType: destinationType.DATA_URL});
          }

        }

        </script>


     </div>
      <div data-role="fieldcontain" data-controltype="camerainput">
        <button onclick="capturePhoto();" data-role="button">Capture Picture of Food</button>
        <img style="display:none; width:60px; height:60px;" id="smallImage" src="" />
      </div>

0 个答案:

没有答案