您好,登錄后才能下訂單哦!
小編給大家分享一下phonegap獲取位置信息的案例,希望大家閱讀完這篇文章后大所收獲,下面讓我們一起去探討吧!
實例如下:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Compass Example</title> <script type="text/javascript" charset="UTF-8" src="cordova.js"></script> <script type="text/javascript" charset="UTF-8"> document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { getPosition(); } //獲取當前位置信息 function getPosition() { navigator.geolocation.getCurrentPosition(onSuccess,onError); } //錯誤的回調(diào) function onError(error) { alert('code:'+error.code+'\n'+'message:'+error.message+'\n'); } //成功的回調(diào) 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獲取位置信息的案例有了一定的了解,想了解更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。