PhoneGap-----Geolocation

<!DOCTYPE html>
<html>
<head>
<title>Device Properties Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="urf-8">
   document.addEventListener("deviceready",onDeviceReady,false);
   var watchID = null;
   function onDeviceReady(){
       var options = { frequency:3000 };
       watchID = navigator.geolocation.watchPosition(onSuccess,onError,options);
   }
   
   function onSuccess(position){
       var element = document.getElementById('geolocation');
       element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
                           'Longitude: '+ position.coords.longitude + '<br />' +
                           '<hr />' + element.innerHTML;
   }
   
   function onError(error){
       alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n');
   }
   
</script>
</head>
<body>
   <p id="geolocation">Watching geolocation...</p>
</body>
</html>

 

posted @ 2014-12-08 12:54  阳光小屋  阅读(102)  评论(0编辑  收藏  举报