geolocation Livewire4+Alpine.jsでの書き方 ==== 位置情報使ってる箇所があったので書き換えてみた。 https://developer.chrome.com/blog/geolocation-html-element?hl=ja 素のhtmlとJavaScriptでは ``` ``` ``` function handleLocation(event) { // Directly access the GeolocationPosition object on the element if (event.target.position) { const { latitude, longitude } = event.target.position.coords; console.log("Location retrieved:", latitude, longitude); } else if (event.target.error) { console.error("Error:", event.target.error.message); } } ``` Livewire4のシングルファイルコンポーネントでは ```
``` `@location`もしくは`x-on:location`で`location`イベントを処理すればいい。 まだポリフィルが必要だけど`@location`を使っているとgeolocation-element-polyfillは動作しないので自力でフォールバックが必要。 ``` ``` `@location`ではなく`x-on:location`で書けばgeolocation-element-polyfillも動作。 ``` @assets @endassets ```