我想從用戶的設備的當前GPS位置,基本上下降緯度和長成表單字段。然後我可以在插入位置後做任何事情。JavaScript表單輸入 - GPS - GeoLocation中
下面的代碼適用於一個彈出警報的位置,這是我開始的。我希望能夠點擊一個按鈕,並將它填入表單字段中的long/lat。
<html>
<head>
<script type="text/javascript">
function getLocationConstant()
{
if(navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(onGeoSuccess,onGeoFormLat,on GeoFormLong,onGeoError);
} else {
alert("Your browser or device doesn't support Geolocation");
}
}
// If we have a successful location update
function onGeoSuccess(event)
{
alert(event.coords.latitude + ', ' + event.coords.longitude);
}
function onGeoFormLat(event)
{
var myVal;
myVal = document.getElementById(event.coords.latitude).value;
}
function onGeoFormLong(event)
{
var myVal;
myVal = document.getElementById(event.coords.longitude).value;
}
// If something has gone wrong with the geolocation request
function onGeoError(event)
{
alert("Error code " + event.code + ". " + event.message);
}
// Called when we want to stop getting location updates
function stopGetLocation(event)
{
navigator.geolocation.clearWatch(watchID);
}
</script>
</head>
<body>
<br><br>
Latitude: <input type="text" id="Latitude" name="onGeoFormLat" value="">
<br><br>
Longitude: <input type="text" id="Longitude" name="onGeoFormLong" value="">
<br>
<br><br><br>
<input type="button" value="Get Location" onclick="getLocationConstant()" />
<br><br>
</body>
</html>
有沒有可能告訴我們在哪些設備上工作? – 2012-04-22 15:20:18
適用於Android平板電腦(Galaxy) - 三星Galaxy II,iPhone,iPad,iPhone ... iPhone/iPad需要位置服務 – 2012-04-22 16:56:55