API vị trí địa lý
Đối tượng vị trí địa lý
Đối tượng Vị trí địa lý cho phép người dùng cung cấp vị trí của họ cho các ứng dụng web. Vì lý do bảo mật, người dùng được yêu cầu cho phép báo cáo thông tin vị trí.
Lưu ý: Tính năng này chỉ khả dụng trong ngữ cảnh an toàn (HTTPS).
Lưu ý: Vị trí địa lý là chính xác nhất cho các thiết bị có GPS, như iPhone.
API vị trí địa lý được xuất bản thông qua đối tượng Navigator.geolocation .
Thuộc tính đối tượng vị trí địa lý
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() |
Phương pháp đối tượng định vị địa lý
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 |