← 返回首页
HTMLGeolocationElement: error プロパティ - Web API | MDN

このページはコミュニティーの尽力で英語から翻訳されました。MDN Web Docs コミュニティーについてもっと知り、仲間になるにはこちらから。

View in English Always switch to English

HTMLGeolocationElement: error プロパティ

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

errorHTMLGeolocationElement インターフェイスの読み取り専用プロパティで、位置データの取得に失敗した場合に、エラー情報を表す GeolocationPositionError オブジェクトを返します。

位置データの取得が成功した場合、そのデータは HTMLGeolocationElement.position プロパティで利用可能です。

In this article

GeolocationPositionError です。位置データの取得に成功した場合は null です。

基本的な使い方

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); } });

error を含む実際の例については、組み込み地図の例の手順を追っての説明をご覧ください。

仕様書

Specification
The HTML Geolocation Element
# dom-htmlgeolocationelement-error

ブラウザーの互換性

Enable JavaScript to view this browser compatibility table.

関連情報