简体   繁体   English

地理定位脚本不起作用? 谁能帮助我我的代码有什么问题

[英]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.

相关问题 正则表达式不起作用。 我的代码有什么问题? 谁能帮我解决这个问题 - Regex doesn't work. What's wrong with my code? Can anyone help me fix this 谁能帮我找出我的表单验证代码有什么问题? - Can anyone help me find out what's wrong with my form validation code? 谁能告诉我这个脚本出了什么问题? - Can anyone tell me what's wrong with this script? 我的Jquery按钮-禁用/启用功能不起作用。 谁能告诉我怎么了? - My Jquery button- disable/enable function is not working. Can anyone tell me what's wrong? 谁能告诉我我的代码有什么问题? - Can anyone tell me what is wrong with my code? 谁能告诉我我的代码有什么问题 - Can anyone tell me what is wrong in my code 有人可以帮我弄清楚我的代码有什么问题吗? 它将 RNA 序列翻译成蛋白质 - Can someone help me figure out what's wrong with my code?. It translates RNA sequences into proteins 任何人都可以帮我弄清楚这个 javascript 有什么问题吗? - Can anyone help me figure out what's wrong in this peice of javascript? 我的js代码出了点大问题,有人可以帮我调试吗? - Something horribly wrong with my js code, anyone can help me debug? 任何人都可以帮我解决我在EventHandler上做错了什么因为某些原因我无法打开Display Conformation框? - Can anyone please help me what I did wrong on my EventHandler for some reason I can't open the Display Conformation box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM