大家好我尝试将当前位置的纬度和经度添加到输入中。
你知道该怎么办吗?这是我的代码
<input type="text" name="demo" id="demo" value="<?php echo $demo ;?>" />
<script>
document.getElementById("demo").value=latitude;
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{
alert("Geolocation is not supported by this browser.");
}
}
function showPosition(position)
{
latitude.innerHTML= position.coords.latitude;
longitude.innerHTML=position.coords.longitude;
}
</script>
答案 0 :(得分:0)
可能我不明白,但如果您打算将坐标添加到文本字段中试试这个
<body>
<script>
function getLocation(){
if (navigator.geolocation){
navigator.geolocation.getCurrentPosition(showPosition);
}else{
alert("Geolocation is not supported by this browser.");
}
}
getLocation()
function showPosition(position) {
var str="Longitude:"+ position.coords.longitude+"Latitude:"+ position.coords.latitude
document.getElementById("demo").value=str
}
</script>
<input type="text" name="demo" id="demo" value="" />
</body>