[英]GeoLocation script not working ? can anyone help me what's wrong in my code
I want latitude and longitude of the current location.我想要当前位置的纬度和经度。
my code我的代码
<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) {
demo.innerHTML ="<form name='formname' action='weather.php' method='GET'> <input type='text' name='lat' id='lat' value='"+position.coords.latitude+"'><br><input type='text' name='long' id='long' value='"+position.coords.longitude+"'><input type='submit' name='submit' value='submit'/></form>";
}
</script>
<div>
<button onclick="getLocation()" name="getlocation" id="getlocation" value="getlocation">Get location</button><br>
<div id='demo'></div>
</div>
the same code working well in the localhost.相同的代码在本地主机中运行良好。 but on the server, it doesn't work.
但是在服务器上,它不起作用。
It will only work if the user allow the website to know its location.只有当用户允许网站知道其位置时,它才会起作用。 otherwise getCurrentPosition() will return "undefined"
否则 getCurrentPosition() 将返回“未定义”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.