Javascript Cordova和多核插件无法协同工作

Javascript Cordova和多核插件无法协同工作,javascript,android,html,cordova,plugins,Javascript,Android,Html,Cordova,Plugins,我目前正在学习这一点,并尝试在我的应用程序中使用多个核心插件,我一直在手动编写代码,然后将其提交给phonegap进行构建和测试。现在,我已经在Windows7上安装了cordova,并按照adobe文档中的说明进行了操作 在phonegap为我构建的应用程序中添加多个核心插件是行不通的。我使用的唯一代码是adobe 3.5版的phonegaps文档。如果你使用一个核心插件,不管它如何工作。此问题所需的所有代码都在其文档中 代码:index.html <!DOCTYPE html&

我目前正在学习这一点,并尝试在我的应用程序中使用多个核心插件,我一直在手动编写代码,然后将其提交给phonegap进行构建和测试。现在,我已经在Windows7上安装了cordova,并按照adobe文档中的说明进行了操作

在phonegap为我构建的应用程序中添加多个核心插件是行不通的。我使用的唯一代码是adobe 3.5版的phonegaps文档。如果你使用一个核心插件,不管它如何工作。此问题所需的所有代码都在其文档中

代码:index.html

    <!DOCTYPE html>
<html>
<head>
    <title>Page Title</title>

    <meta name="viewport" content="width=device-width, initial-scale=1">

    <link rel="stylesheet" href="css/themes/default/jquery.mobile-1.4.3.min.css" />
    <link rel="stylesheet" href="css/animate.min.css" />
    <script src="js/jquery.js"></script>
    <script src="js/jquery.mobile-1.4.3.min.js"></script>
    <script src="cordova.js"></script>

    <script>

    </script>
</head>
<body>

<!--/////////////////////////////Home - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<div data-role="page" id="home">

    <div data-role="header">
        <h1>API</h1>
    </div><!-- /header -->

    <div role="main" class="ui-content">
        <ul data-role="listview">
            <li><a href="#accel" onclick="readyAccel();">Accelerometer</a></li>
            <li><a href="#gps" onclick="readyGPS();">GPS</a></li>
            <li><a href="#compass" onclick="readyCompass();">Compass</a></li>
        </ul>
    </div><!-- /content -->

    <div data-role="footer" data-position="fixed">
        <h4>Joshua</h4>
    </div><!-- /footer -->
</div><!-- /page -->

<!--/////////////////////////////Home - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->    

<!--/////////////////////////////Accel - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<div data-role="page" id="accel">
    <div data-role="header">
        <h1>Accelerometer</h1>
    </div><!-- /header -->

    <script>

             // The watch id references the current `watchAcceleration`
            var AccelID = null;

            // Wait for device API libraries to load
            //
            function readyAccel() {
                document.addEventListener("deviceready", onDeviceReadyAccel, false);
            }
            // device APIs are available
            //
            function onDeviceReadyAccel() {
                startAccel();
            }

            // Start watching the acceleration
            //
            function startAccel() {

                // Update acceleration every .1 seconds
                var options = { frequency: 100 };

                AccelID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
            }

            // Stop watching the acceleration
            //
            function stopAccel() {
                if (AccelID) {
                    navigator.accelerometer.clearWatch(AccelID);
                    AccelID = null;
                }
            }

            // onSuccess: Get a snapshot of the current acceleration
            //
            function onSuccess(acceleration) {
                var element = document.getElementById('accelerometer');

                element.innerHTML = 'Acceleration X: ' + acceleration.x + '<br />' +
                                    'Acceleration Y: ' + acceleration.y + '<br />' +
                                    'Acceleration Z: ' + acceleration.z + '<br />' +
                                    'Timestamp: '      + acceleration.timestamp + '<br />';
            }

            // onError: Failed to get the acceleration
            //
            function onError() {
                alert('onError!');
            }
        if(!isset($element)) {
            alert('failed');
        }
    </script>
  </head>
  <body>
    <div id="accelerometer">Waiting for accelerometer...</div>
        <button onclick="stopAccel();">Stop Watching</button>
</div>

<!--/////////////////////////////Accel - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<!--/////////////////////////////GPS - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<div data-role="page" id="gps">
    <div data-role="header">
        <h1>GPS</h1>
    </div>

    <script>

        // Wait for device API libraries to load
        //
        function readyGPS() {
            document.addEventListener("deviceready", onDeviceReadyGeo, false);
        }

        var GeoID = null;

        // device APIs are available
        //
        function onDeviceReadyGeo() {
            // Get the most accurate position updates available on the
            // device.
            var options = { enableHighAccuracy: true };
            GeoID = navigator.geolocation.watchPosition(onSuccess, onError, options);
        }

        // onSuccess Geolocation
        //
        function onSuccess(position) {
            var element = document.getElementById('geolocation');
            element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                                'Longitude: ' + position.coords.longitude     + '<br />' +
                                '<hr />'      + element.innerHTML;
        }

        // clear the watch that was started earlier
        //
        function clearGeo() {
            if (GeoID != null) {
                navigator.geolocation.clearWatch(GeoID);
                GeoID = null;
            }
        }

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


   ////////Default Script Start\\\\\\\\\\

//    // Wait for device API libraries to load
//    //
//    document.addEventListener("deviceready", onDeviceReady, false);
//
//    var watchID = null;
//
//    // device APIs are available
//    //
//    function onDeviceReady() {
//        // Get the most accurate position updates available on the
//        // device.
//        var options = { enableHighAccuracy: true };
//        watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
//    }
//
//    // onSuccess Geolocation
//    //
//    function onSuccess(position) {
//        var element = document.getElementById('geolocation');
//        element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
//                            'Longitude: ' + position.coords.longitude     + '<br />' +
//                            '<hr />'      + element.innerHTML;
//    }
//
//    // clear the watch that was started earlier
//    //
//    function clearWatch() {
//        if (watchID != null) {
//            navigator.geolocation.clearWatch(watchID);
//            watchID = null;
//        }
//    }
//
//        // onError Callback receives a PositionError object
//        //
//        function onError(error) {
//          alert('code: '    + error.code    + '\n' +
//                'message: ' + error.message + '\n');
//        }

    //////////Default Script End\\\\\\\\\\\\\\\\\

    </script>

  </head>
  <body>

<!--
    <p id="geolocation">Watching geolocation...</p>
    <button onclick="clearGeo();">Clear Location</button>
-->

      <p id="geolocation">Watching geolocation...</p>
        <button onclick="clearWatch();">Clear Watch</button>

</div>    

<!--/////////////////////////////GPS - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<!--/////////////////////////////COMPASS - API \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

<div data-role="page" id="compass">
    <div data-role="header">
        <h1>Compass</h1>
    </div>

    <script>

        // The watch id references the current `watchHeading`
        var CompassID = null;

        // Wait for device API libraries to load
        //
        function readyCompass() {
            document.addEventListener("deviceready", onDeviceReadyCompass, false);
        }
        // device APIs are available
        //
        function onDeviceReadyCompass() {
            startCompass();
        }

        // Start watching the compass
        //
        function startCompass() {

            // Update compass every .1 seconds
            var options = { frequency: 100 };

            CompassID = navigator.compass.watchHeading(onSuccess, onError, options);
        }

        // Stop watching the compass
        //
        function stopCompass() {
            if (CompassID) {
                navigator.compass.clearWatch(CompassID);
                CompassID = null;
            }
        }

        // onSuccess: Get the current heading
        //
        function onSuccess(heading) {
            var element = document.getElementById('heading');
            element.innerHTML = 'Heading: ' + heading.magneticHeading;
        }

        // onError: Failed to get the heading
        //
        function onError(compassError) {
            alert('Compass error: ' + compassError.code);
        }

    </script>
  </head>
  <body>

    <div id="heading">Waiting for heading...</div>
    <button onclick="stopCompass();">Stop Compass</button>

</div>    
<!--/////////////////////////////COMPASS - API - END \\\\\\\\\\\\\\\\\\\\\\\\\\\\\-->

</body>
</html>
代码:config.xml

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.hellocordova" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <preference name="loglevel" value="DEBUG" />
    <preference name="AndroidLaunchMode" value="singleTop" />
    <feature name="App">
        <param name="android-package" value="org.apache.cordova.App" />
    </feature>
    <feature name="Accelerometer">
        <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener" />
    </feature>
    <feature name="Compass">
        <param name="android-package" value="org.apache.cordova.deviceorientation.CompassListener" />
    </feature>
    <name>App Multi</name>
    <description>
        "Multi plugins"
    </description>
    <author email="email@address.com" href="http://google.com">
        Joshua
    </author>
    <content src="index.html" />
    <access origin="*" />
</widget>
我已经更改了watchID,看看它是否与其他插件冲突,但是这不起作用

链接到API的JS:-

加速计: 全球定位系统:
我最多只能发布两个链接,因此我认为您可以很容易地从phonegaps文档中找到指南针。

这对于任何提供帮助的人来说都是非常模糊的。请您添加一些特定的信息,例如您正在尝试使用哪些插件,您正在为哪些平台构建插件,并为您发现问题的插件添加一些JS。谢谢,有人吗?有人吗?那么,cordova不能利用多个插件?我不知疲倦地搜索,只找到了单一插件解决方案。