diff --git a/loc-chase2.js b/loc-chase2.js index f12e315..461fb96 100644 --- a/loc-chase2.js +++ b/loc-chase2.js @@ -32,14 +32,10 @@ document.getElementById("title").textContent = "START!!"; } - function onSuccess(pos) { - var latlng = L.latLng( - pos.coords.latitude, - pos.coords.longitude - ); + function updateLocation(lat, lng) { + const latlng = L.latLng(lat, lng); mymap.panTo(latlng); - // ★★★★★ ここから(課題部分) const goalLat = 38.892; const goalLng = 139.825; @@ -60,7 +56,13 @@ .setLatLng(latlng) .setPopupContent(message) .openPopup(); - // ★★★★★ ここまで + } + + function onSuccess(pos) { + updateLocation( + pos.coords.latitude, + pos.coords.longitude + ); } function onError(err) { @@ -71,9 +73,17 @@ } } - // ★ ボタン設定はここ + mymap.on("click", function (e) { + updateLocation( + e.latlng.lat, + e.latlng.lng + ); + }); + + document.getElementById("start") .addEventListener("click", tryWatchLOC); + document.getElementById("stop") .addEventListener("click", stopLOC);