[英]HTML5 Geolocation Trouble
I am writing a Java script for HTML 5 geolocation but it doesnt seem to work and when I try to output the contents in another scope, it says undefined. 我正在为HTML 5地理定位编写Java脚本,但是它似乎不起作用,当我尝试在另一个作用域中输出内容时,它说未定义。 Below is the code.
下面是代码。
<script>
var lat;
var lng;
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{}
}
function showPosition(position)
{
lat = position.coords.latitude;
lng = position.coords.longitude;
document.write(lat); // Doesnt output anything
}
</script>
<script type="text/javascript">
document.write(lat); // It says undefined
$(document).ready(function()
{
//some scripts here
}
</script>
The success callback functions are called only when the html page is hosted on a web server, not in localhost. 仅当html页面托管在Web服务器上而不是localhost中时,才调用成功回调函数。 Are you testing locally or on a webserver?
您是在本地还是在Web服务器上进行测试?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.