คุณสมบัติ Geolocation coordinates
- หน้าก่อน coordinates
- หน้าต่อไป getCurrentPosition()
- กลับไปยังเพจต้น วัตถุ Geolocation
คำนิยามและวิธีใช้
coordinates คุณสมบัติกลับค่าตำแหน่งและความสูงของอุปกรณ์บนโลก
ตัวอย่าง
หาตำแหน่งทิศทางของผู้ใช้:
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; }
Coordinates คุณสมบัติ
คุณสมบัติ | รายละเอียด |
---|---|
coordinates.latitude | ความกว้างทิศของตำแหน่งที่ตั้ง นับด้วยองศาเดซิมาล |
coordinates.longitude | ความยาวทิศของตำแหน่งที่ตั้ง นับด้วยองศาเดซิ�าล |
coordinates.altitude | ความสูงของตำแหน่งที่ตั้ง ต่อจากระดับน้ำทะเล นับด้วยเมตร |
coordinates.accuracy | ความเชิงมาตรของ latitude และ longitude ค่านี้นับด้วยเมตร |
coordinates.altitudeAccuracy | ความเชิงมาตรของ altitude ค่านี้นับด้วยเมตร |
coordinates.heading | ความทิศทางที่อุปกรณ์เดินทาง ค่านี้นับด้วยองศา แสดงว่าอุปกรณ์ห่างจากทิศเหนือที่ตรงข้ามไหน 0 องศาเป็นทิศเหนือ ทิศทางวนอ้อม (ตะวันออก 90 องศา ตะวันตก 270 องศา) ถ้าความเร็วเท่า 0 แล้ว heading จะเป็น NaN ถ้าอุปกรณ์ไม่สามารถให้ข้อมูลทิศทางได้ ค่านี้จะเป็น null |
coordinates.speed | ความเร็วของอุปกรณ์ ด้วยหน่วยเมตรต่อวินาที ค่านี้สามารถเป็น null ได้ |
การสนับสนุนโดยเบราเซอร์
คุณสมบัติ | Chrome | IE | Firefox | Safari | Opera |
---|---|---|---|---|---|
coordinates | 5.0 | 9.0 | 3.5 | 5.0 | 10.6 |
- หน้าก่อน coordinates
- หน้าต่อไป getCurrentPosition()
- กลับไปยังเพจต้น วัตถุ Geolocation