Geolocation API
วัตถุตำแหน่งทางภูมิศาสตร์
วัตถุ Geolocation อนุญาตให้ผู้ใช้ระบุตำแหน่งของตนกับเว็บแอปพลิเคชัน ด้วยเหตุผลด้านความเป็นส่วนตัว ผู้ใช้จะต้องได้รับอนุญาตให้รายงานข้อมูลตำแหน่ง
หมายเหตุ:ฟีเจอร์นี้ใช้ได้เฉพาะในบริบทที่ปลอดภัย (HTTPS)
หมายเหตุ: การระบุตำแหน่งทางภูมิศาสตร์นั้นแม่นยำที่สุดสำหรับอุปกรณ์ที่มี GPS เช่น iPhone
Geolocation API เผยแพร่ผ่าน อ็อบเจ็กต์navigator.geolocation
คุณสมบัติวัตถุตำแหน่งทางภูมิศาสตร์
Property | Description |
---|---|
coordinates | Returns the position and altitude of the device on Earth |
position | Returns the position of the concerned device at a given time |
positionError | Returns the reason of an error occurring when using the geolocating device |
positionOptions | Describes an object containing option properties to pass as a parameter of Geolocation.getCurrentPosition() and Geolocation.watchPosition() |
วิธีการระบุตำแหน่งวัตถุ
Method | Description |
---|---|
clearWatch() | Unregister location/error monitoring handlers previously installed using Geolocation.watchPosition() |
getCurrentPosition() | Returns the current position of the device |
watchPosition() | Returns a watch ID value that then can be used to unregister the handler by passing it to the Geolocation.clearWatch() method |