<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) {
"Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
$("#Latitude").val(position.coords.latitude);
$("#Longitude").val(position.coords.longitude);
}
</script>
ลองดูครับ แต่ Server ต้อง HTTPS ด้วยนะครับ ไม่งั้นจะไม่ขึ้น แต่ถ้าทดสอบบน localhost ขึ้นครับ
<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) {
"Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
$("#Latitude").val(position.coords.latitude);
$("#Longitude").val(position.coords.longitude);
}
</script>