diff --git a/map4.html b/map4.html index 245229e..a3c0ce5 100644 --- a/map4.html +++ b/map4.html @@ -2,7 +2,7 @@ - 現在地マップ + グループ位置共有マップ @@ -12,121 +12,85 @@ - -
- - -
-

現在地を表示しています

-

位置情報の取得を許可してください。

- グループ選択に戻る -
- - -
- +
+
+

現在地を表示しています

+

位置情報の取得を許可してください。

+ グループ選択に戻る
- + navigator.geolocation.getCurrentPosition( + function (pos) { + const lat = pos.coords.latitude; + const lng = pos.coords.longitude; + + map.flyTo([lat, lng], 17, { duration: 2 }); + + const me = { id: 'me', lat: lat, lng: lng }; + updateMembers([me]); + + // 3秒ごとに他ユーザーの位置取得 + setInterval(() => { + fetch("../mycgi/map1/load_locations.rb?group=" + group) + .then(res => res.json()) + .then(data => { + const allUsers = [me, ...data.locations.filter(u => u.id !== 'me')]; + updateMembers(allUsers); + }); + }, 3000); + }, + function (error) { + alert("位置情報が取得できませんでした"); + } + ); + } + + moveToCurrentLocation(); +