如何將JavaScript位置(經度和緯度)值傳遞給Textbox值?
<body>
<button onclick="getLocation()">Get coordinates</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude;
}
</script>
<input type="text" value="long,lati"></input>
</body>
我需要在腳本到文本框中的緯度和經度沒有onclocking按鈕按代碼。
只需調用函數'getLocation()' – Rayon
你的意思是什麼文本框? ' Grundy