HTML5地理位置无法在本地系统中使用 [英] HTML5 Geolocation Not working in local system

查看:296
本文介绍了HTML5地理位置无法在本地系统中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在编写一个简单的代码来测试HTML5中的地理位置功能;我正在练习来自www.w3schools.com的代码,该代码在网站上运行正常.但是,当我在文本板中编写相同的代码并将其另存为HTML时,在请求共享位置的权限后,它显示空白页.是否需要将网页托管在某个服务器上,然后才可以正常工作?
我使用的代码是:-

Hi,

I am writing a simple code to test the geolocation feature in HTML5; I am practicing the code from www.w3schools.com and it is working fine in the website. But when I write the same code in a textpad and save it as HTML, after asking permission for sharing the location it is showing blank page. Is it something like I need to host the web-page in some server and then only it will work?
the code I am using is :-

<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to get your coordinates:</p>
<button  önclick="getLocation()">Try It</button>
<script>
//var x=document.getElementById("demo");
function getLocation()
  {
  if (navigator.geolocation)
    {
	alert("it works");
    navigator.geolocation.getCurrentPosition(showPosition);
    }
  else
  {
  alert("Geolocation is not supported by this browser.");
  }
  }
function showPosition(position)
  {
  alert("Latitude: " + position.coords.latitude + 
  "<br />Longitude: " + position.coords.longitude);	
  }
</script>
</body>
</html>




请帮忙............
谢谢
Jashobanta




Please help............
Thanks
Jashobanta

推荐答案

经过一些测试和研究,我发现了这一点:
另外,还有一个有趣的链接-
http://thoughtresults.com/geolocation-api [
After a little testing and research, I found this: http://stackoverflow.com/questions/5423938/html-5-geo-location-prompt-in-chrome[^]. I happened to have Python installed, so I copied a test file to the Python directory, started the web server the link mentions with "python -m SimpleHTTPServer", and confirmed it worked. With my Chrome browser, I did see that Chrome was blocking the Geolocation request from the local file.

Also, another interesting link - http://thoughtresults.com/geolocation-api[^]
Scott


这篇关于HTML5地理位置无法在本地系统中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆