navigator.geolocation.getCurrentPosition always fail in chrome and firefox

后端 未结 7 752
予麋鹿
予麋鹿 2020-12-16 02:04

I got strange behavior when I tried to test my \"navigator.geolocation.getCurrentPosition\" web page. Here is my testing result and code:

my code:

fu         


        
相关标签:
7条回答
  • 2020-12-16 02:37

    This will print the Latitude and Longitude of your Location

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
      <script>
        function getLocation() {
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(showPosition);
            } else { 
                alert("Geolocation is not supported by this browser.");
            }
    
        }
        function showPosition(position) {
            document.getElementById('idLatitude').value = position.coords.latitude;
            document.getElementById('idLongitude').value = position.coords.longitude;
    
        }
        </script>
    
    </head>
    <body onload="getLocation()">
    <form action="HelloWorld" method="post">
        <input id="idLatitude"  type="text" name="strLatitude">
        <input id="idLongitude" type="text" name="strLongitude">
    
    </form>
    </body>
    </html>
    

    0 讨论(0)
提交回复
热议问题