2017-06-26 4 views
0

Zunächst ich leeres Projekt erstellt mitReference: cordova nicht ionische definiert

ionic start checkGPS blank 

Danach i-Plugin installiert -

cordova.plugins.diagnostic 

Ich habe in www folgenden Code/index.html

cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ 
    console.log("GPS location is " + (enabled ? "enabled" : "disabled")); 
}, function(error){ 
    console.error("The following error occurred: "+error); 
}) 

Suchen in der config.xml & package.json Plugin Informationen sind bereits vorhanden y hinzugefügt, auch ich habe versucht, cordova.js

zu addieren Aber es hat nicht funktioniert, obwohl!

Index.HTML

<!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 rel="manifest" href="manifest.json"> 
    <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> 
    <script src="cordova.js"></script> 
    <script src="js/app.js"></script> 
    <script type="text/javascript"> 
    document.addEventListener("deviceready", function() { 
     cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ 
      console.log("GPS location is " + (enabled ? "enabled" : "disabled")); 
      alert('hello'); 
     }, function(error){ 
      console.error("The following error occurred: "+error); 
     }) 
    }, false); 
    </script> 
    </head> 
    <body ng-app="starter"> 
    <ion-pane> 
     <ion-header-bar class="bar-stable"> 
     <h1 class="title">Ionic Blank Starter</h1> 
     </ion-header-bar> 
     <ion-content> 
     </ion-content> 
    </ion-pane> 
    </body> 
</html> 
+0

Ja, ich hinzugefügt ... –

+0

Sie sind sicher, dass nicht bekommt einen 404-Fehler in der Zeile ' '? Bitte überprüfen Sie Ihre App und überprüfen Sie die Konsolenausgabe. –

+0

Testen Sie in einem Browser oder in einem echten Gerät? –

Antwort

0

Wahrscheinlich tritt das Problem auf, da das Gerät nicht bereit ist. Versuchen Sie, Ihren Code im Lebenszyklus-Ereignis deviceready() hinzuzufügen. Wie folgt aus:

document.addEventListener("deviceready", function() { 
    cordova.plugins.diagnostic.isGpsLocationEnabled(function(enabled){ 
     console.log("GPS location is " + (enabled ? "enabled" : "disabled")); 
    }, function(error){ 
     console.error("The following error occurred: "+error); 
    }) 
}, false); 
+0

- Ich habe Ihren Code versucht, aber nicht funktioniert. –

+0

Bitte aktualisieren Sie Ihre Frage mit der vollständigen index.html Datei. –

+0

Ja, erledigt bitte überprüfen –

Verwandte Themen