【发布时间】:2013-06-23 01:51:12
【问题描述】:
我正在尝试使用 Jquery 在我的移动应用程序中获取当前位置。我按照本教程进行操作,并复制了示例。我将文件保存为 .html 文件并尝试从手机打开。代码无法获取当前的经纬度。
显示当前 GPS 坐标
<!DOCTYPE html>
<html>
<head>
<meta name=viewport content="user-scalable=no,width=device-width" />
<link rel=stylesheet href=jquery.mobile/jquery.mobile.css />
<script src=jquery.js></script>
<script src=jquery.mobile/jquery.mobile.js></script>
</head>
<body>
<div data-role=page id=home>
<div data-role=header>
<h1>Home</h1>
</div>
<div data-role=content>
<span> Latitude : </span> <span id=lat></span> <br />
<span> Longitude : </span> <span id=lng></span> <br />
</div>
</div>
</body>
</html>
<script>
navigator.geolocation.getCurrentPosition (function (pos)
{
var lat = pos.coords.latitude;
var lng = pos.coords.longitude;
$("#lat").text (lat);
$("#lng").text (lng);
});
</script>
【问题讨论】:
-
三星硬件以 navigator.geolocation.getCurrentPosition 的问题而闻名。例如,我有 Galaxy S2 和 S3,它们都无法让 getCurrentPosition 函数工作。
标签: jquery google-maps jquery-mobile gps