phonegap获取位置信息详解
这次给大家带来phonegap获取位置信息详解,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); } //错误的回调 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操作数据库详解
不刷新的前提下怎样改变当前url的代码
以上就是phonegap获取位置信息详解的详细内容,更多请关注其它相关文章!
- phonegap操作数据库详解
- phonegap播放音频详解