android - Androip phonegap GPS accuracy -


in following code trying gps location phonegap example.iam trying on actual device , not on emulator time out every time.i never got on success alert.what doing wrong.i have enable gps , internet

js

document.addeventlistener("deviceready", ondeviceready, false);  var watchid = null;  // cordova ready // function ondeviceready() { // throw error if no update received every 30 seconds var options = { timeout: 30000 }; 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; }  // onerror callback receives positionerror object // function onerror(error) { alert('code: '    + error.code    + '\n' +       'message: ' + error.message + '\n'); } 

html

 <html>  <head>  <title>cordova</title>  <script type="text/javascript" charset="utf-8" src="cordova-2.1.0.js"></script>  <script type="text/javascript" src="js/jquery.mobile-1.2.0/jquery-1.8.1.min.js"></script>  <script type="text/javascript" src="js/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.js"> </script>  <link rel="stylesheet" href="js/jquery.mobile-1.2.0/jquery.mobile-1.2.0.min.css" />  <script type="text/javascript" src="js/index.js"></script>  </head>  <body >  <h1>hello world</h1>  <p id="geolocation">finding geolocation...</p>  </body>  </html> 

try options:

var options = { timeout: 30000, enablehighaccuracy: true };  

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -