【发布时间】:2021-12-22 00:33:42
【问题描述】:
我是堆栈溢出的新手,因为遇到错误而注册。 这是为我即将到来的高中项目准备的!
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<html>
<body>
<form>
<input type="button" value="Result" onclick="getGeolocation" />
<input type="button" value="Result" onclick="getUserCoodinates" />
</form>
<script type="text/javascript">
// <![CDATA[
//run this code when the page loads
jQuery(document).ready(function() {
getGeolocation();
});
//determine if the user's browser has location services enabled. If not, show a message
function getGeolocation() {
if (navigator.geolocation) {
//if location services are turned on, continue and call the getUserCoordinates function below
navigator.geolocation.getCurrentPosition(getUserCoodinates);
} else {
alert('You must enable your device\'s location services in order to run this application.');
}
}
//function is passed a position object which contains the lat and long value
function getUserCoodinates(position) {
//set the application's text inputs LAT and LONG = to the user's lat and long position
jQuery("#LAT").val(position.coords.latitude);
jQuery("#LONG").val(position.coords.longitude);
}
</script>
</body>
</html>
我哪里出错了? ? ?
我正在尝试将其用于移动网络应用程序。
【问题讨论】:
-
地理位置 API 仅在网络服务器/域上激活 SSL 证书时可用
-
getUserCoodinates需要position作为唯一提供的参数 - 在这里使用onclick会失败,因为position是通过地理位置回调获得的,所以基本上<input type="button" value="Result" onclick="getUserCoodinates"/>是不正确
标签: javascript html jquery css html5-canvas