HTMLGeolocationElement: thuộc tính error
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Thuộc tính error chỉ đọc của giao diện HTMLGeolocationElement trả về một đối tượng GeolocationPositionError đại diện cho thông tin lỗi, trong trường hợp không lấy được dữ liệu vị trí.
Nếu việc lấy dữ liệu vị trí thành công, dữ liệu sẽ có sẵn trong thuộc tính HTMLGeolocationElement.position.
Giá trị
Một đối tượng GeolocationPositionError, hoặc null nếu dữ liệu vị trí được lấy thành công.
Ví dụ
>Sử dụng cơ bản
html
<geolocation autolocate></geolocation>
js
const geo = document.querySelector("geolocation");
geo.addEventListener("location", () => {
if (geo.position) {
console.log(
`(${geo.position.coords.latitude},${geo.position.coords.longitude})`,
);
} else if (geo.error) {
console.log(geo.error.message);
}
});
Xem hướng dẫn ví dụ bản đồ nhúng để có ví dụ thực tế bao gồm error.
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| The HTML Geolocation Element> # dom-htmlgeolocationelement-error> |