diff --git a/loc-chase2.js b/loc-chase2.js index 6c45c3b..6fcc366 100644 --- a/loc-chase2.js +++ b/loc-chase2.js @@ -1,5 +1,4 @@ document.addEventListener("DOMContentLoaded", () => { - var mymap = L.map("locationmap").setView([38.891, 139.824], 16); L.tileLayer("https://{s}.tile.osm.org/{z}/{x}/{y}.png", { @@ -32,9 +31,7 @@ document.getElementById("title").textContent = "START!!"; } - // =================================== - // ★ 共通処理(GPSでもクリックでも使う) - // =================================== + // 共通処理 function updateLocation(latlng) { mymap.panTo(latlng); @@ -46,9 +43,9 @@ let message; - if (dLat < 0.0003 && dLng < 0.0003) { + if (dLat < 0.001 && dLng < 0.001) { message = "🎉 GOAL!! 宝を見つけました!"; - } else if (dLat < 0.001 && dLng < 0.001) { + } else if (dLat < 0.005 && dLng < 0.005) { message = "おしい!もう少し!"; } else { message = "探索中…"; @@ -60,9 +57,7 @@ .openPopup(); } - // =================================== // GPS 成功時 - // =================================== function onSuccess(pos) { var latlng = L.latLng( pos.coords.latitude, @@ -79,17 +74,21 @@ } } - // =================================== - // ★ 地図クリック対応(追加部分) - // =================================== + // 地図クリック対応 mymap.on("click", function (e) { - stopLOC(); // GPSを止める - updateLocation(e.latlng); // クリック位置で判定 + console.log("クリック:", e.latlng); + stopLOC(); + updateLocation(e.latlng); }); - // =================================== + // スマホタップ対応 + mymap.on("tap", function (e) { + console.log("タップ:", e.latlng); + stopLOC(); + updateLocation(e.latlng); + }); + // ボタン設定 - // =================================== document.getElementById("start") .addEventListener("click", tryWatchLOC);