【发布时间】:2019-02-26 19:18:40
【问题描述】:
请帮忙!如何通过“#btn_2”点击获取我手机的经纬度? 对于 index.html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" type="text/css" href="css/index.css">
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/bootstrap.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</head>
<body onload="Ready()">
<div class=".app">
<form style="padding: 15px" id="form_1" name="form_1">
<br>
<button type="Submit" id="btn_2">geo location</button>
</form>
<span id="result"></span>
</div>
</body>
</html>
对于 index.js:
function Ready(){
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady(){
$(document).ready(function(){
$('#btn_2').click(function(){
navigator.geolocation.getCurrentPosition(onSuccess, onError, {
timeout: 5000, enableHighAccuracy: true });
});
});
}
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');
};
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
当尝试点击我手机中的按钮时,它没有显示任何警报,既没有成功也没有错误警报。请帮忙!
【问题讨论】:
标签: javascript android html css cordova