Get current location latitude and longitude using jQuery:
Hello guys, here I will discuss about the Geolocation latitude and longitude using simple jQuery code. In this tutorial I will provide some code, those codes help you to get a current location latitude and longitude value.
I am creating a form in the example and define a submit button. When click the submit button it will get the current location latitude and longitude value, those values pass by URL which URL link you can define in the form action.
If you want to display a user Geolocation by using latitude and longitude, you can do it to get latitude and longitude value from the URL.
For Example:
<!DOCTYPE html> <html> <head> <title></title> </head> <body> <form id="myForm" method="GET" action="index.php" > <input type="button" value="Stores" onclick="getLocation()"> <input id="latitudeId" type="hidden" > <input id="longitudeId" type="hidden" > </form> <p id="show"></p> <script> function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else { document.getElementById("show").innerHTML = "Geolocation is not supported by this browser."; } } function showPosition(position) { document.getElementById("latitudeId").value = position.coords.latitude; document.getElementById("longitudeId").value = position.coords.longitude; document.getElementById('myForm').submit(); } </script> </body> </html>
Related posts