ตัวอย่าง Javascript หาตำแหน่ง GPS location latitude longitude
ตัวอย่าง javascript ในการหาตำแหน่ง GPS ตามด้านล่างครับ
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 = "GPS LOCATION :"+position.coords.latitude+","+position.coords.longitude;
}
ตามนี้เลยครับ หรือถ้าใครจะส่งเป็น Link เข้า Google Map ก็ทำได้ตามด้านล่าง
href='https://www.google.com/maps/@"+position.coords.latitude+","+position.coords.longitude+",15z'