cordova插件- Geolocation
小编:管理员 488阅读 2022.09.13
- 添加插件
$ cordova plugin add cordova-plugin-geolocation
- 插件的使用
- Methods
- navigator.geolocation.getCurrentPosition
- navigator.geolocation.watchPosition
- navigator.geolocation.clearWatch
2. Example
function locationClik() { navigator.geolocation.getCurrentPosition(onSuccess, onError); } // onSuccess Callback // This method accepts a Position object, which contains the // current GPS coordinates // var onSuccess = function(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: ' + position.timestamp + '\n'); }; // onError Callback receives a PositionError object // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } /////////////////////////////////////////////////////////////////////////////////// // onSuccess Callback // This method accepts a `Position` object, which contains // the current GPS coordinates // function onSuccess(position) { var element = document.getElementById('geolocation'); element.innerHTML = 'Latitude: ' + position.coords.latitude + '复制
' + 'Longitude: ' + position.coords.longitude + '
' + '
' + element.innerHTML; } // onError Callback receives a PositionError object // function onError(error) { alert('code: ' + error.code + '\n' + 'message: ' + error.message + '\n'); } // Options: throw an error if no update is received every 30 seconds. // var watchID; function locationTimeClik() { watchID = navigator.geolocation.watchPosition(onSuccess, onError, { timeout: 30000 }); } ////////////////////////////////////////////////////////////// function clearTimeClik() { navigator.geolocation.clearWatch(watchID); }
相关推荐
- Cordova 什么是Cordova? Cordova是用于使用HTML,CSS和JS构建移动应用的平台。我们可以认为Cordova是一个容器,用于将我们的网络应用程序与本机移动功能连接。默认情况下,Web应用程序不能使用本机移动功能。这就是Cordova进来的地方。它为网络应用和移动设备之间的连…
- 3DMAX提示和技巧 本主题标识使用 Civil View 的一些重要提示和技巧。常规使用屏幕分辨率至少为 1280x1024 的 Civil View。低于此分辨率时,一些面板将占用过多屏幕空间。 将视口设置为线框显示以达到最佳性能。 要尽可能简化用户界面,请在单个视口中工作并关闭 3ds Max 命令面…