简体   繁体   中英

how to get latitude and longitude of user by hidden form input

I want to get latitude and longitude of user when he fill form on my website .. when i use this code from w3school my website not show any results because may be server prevent that ... can you help me to get another method please ??

 <p>Click the button to get your coordinates.</p> <button onclick="getLocation()">Try It</button> <p id="demo"></p> <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) { x.innerHTML = "Latitude: " + position.coords.latitude + "<br>Longitude: " + position.coords.longitude; } </script> 

Works fine on jsbin.

Please check the browser support at w3schools

w3schools also mentions -

As of Chrome 50, the Geolocation API will only work on secure contexts such as HTTPS.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM