应用phonegap获得部位信息内容的完成方式

2021-02-24 00:10 jianzhan

案例以下:

<!DOCTYPE html> 
<html> 
  
    <head> 
        <meta charset="UTF⑻"> 
        <title>Compass Example</title> 
  
        <script type="text/javascript" charset="UTF⑻" src="cordova.js"></script> 
        <script type="text/javascript" charset="UTF⑻"> 
            document.addEventListener("deviceready", onDeviceReady, false); 
  
            function onDeviceReady() { 
                getPosition(); 
            } 
              
            //获得当今部位信息内容 
            function getPosition() { 
                navigator.geolocation.getCurrentPosition(onSuccess,onError); 
            } 
  
  
            //不正确的回调函数  
            function onError(error) { 
                alert('code:'+error.code+'\n'+'message:'+error.message+'\n'); 
            } 
  
            //取得成功的回调函数  
            function onSuccess(position) { 
                alert('Latitude:'+position.coords.latitude+'\n'+ 
                'Longitude:'+position.coords.longitude+'\n'+ 
                'Altitude:'+position.coords.altitude+'\n'+ 
                'Accuracy:'+position.coords.accuracy+'\n'+ 
                'Altitude Accuracy:'+position.coords.altitudeAccuracy+'\n'+ 
                'Heading:'+position.coords.heading+'\n'+ 
                'Speed:'+position.coords.speed+'\n'+ 
                'Timestamp:'+new Date(position.timeStamp)+'\n'); 
            } 
        </script> 
    </head> 
  
    <body> 
        <button onclick="getPosition();">Start Watching</button> 
    </body> 
  
</html>

以上这篇应用phonegap获得部位信息内容的完成方式便是网编共享给大伙儿的所有內容了,期待能给大伙儿1个参照,也期待大伙儿多多适用脚本制作之家。