我正在尝试创建一个多页移动应用程序,希望只有两页,并希望将地理位置纬度和经度放入两个单独的表单文本输入中。我希望这可以通过按钮按下或点击。
我真的不知道如何:
这是我到目前为止所做的:
<div data-role="fieldcontain">
<label for="GPS Location">GPS Lat</label>
<input name="GPS Lat" id="GPSlat" value="" type="text">
</div>
<div data-role="fieldcontain">
<label for="GPS Location">GPS Long</label>
<input name="GPS Long" id="GPSlong" value="" type="text">
</div>
<div data-role="content">
<script type="text/javascript">
navigator.geolocation.getCurrentPosition(function(position)
{
var lat = pos.coordinates.latitude;
var lng = pos.coordinates.longitude;
console.log( lat + ":" + lng);
});
</script>
</div>
<input value="SetGPS" id="SetGPS" data-inline="true" type="submit">
<br>
<div data-role="content">
<script type="text/javascript">
$("#SetGPS").click(function(){
$("#GPSlat input").text(lat);
$("#GPSlong input").text(lng)
</script>
</div>
答案 0 :(得分:0)
您刚刚提出了一些名称和语法错误:
getCurrentPosition
所做的功能采用了一个名为position
的参数,但您在其中引用了pos
。lat
和lng
在上述函数中定义,因此click
函数无法使用它们coordinates
,但字段为is actually called coords
。input#id
以下是您的代码应该是什么样的:
var lat, lng;
navigator.geolocation.getCurrentPosition(function(position)
{
lat = position.coords.latitude;
lng = position.coords.longitude;
console.log( lat + ":" + lng);
});
// ...
$("#SetGPS").click(function()
{
$("input#GPSlat").val(lat);
$("input#GPSlong").val(lng);
});