diff --git a/map/gps/gps-chase.js b/map/gps/gps-chase.js index 4f0e1d0..4bcde4a 100644 --- a/map/gps/gps-chase.js +++ b/map/gps/gps-chase.js @@ -8,7 +8,7 @@ var gpsmarker = L.marker(mymap.getCenter()).addTo(mymap); gpsmarker.bindPopup("STARTおしてね").openPopup(); - + var nTrial = 100 var watchId = null; // 最初はnullにしておく function stopGPS() { // watchが動いていたら止めてnullにする @@ -35,25 +35,23 @@ gpsmarker.setLatLng(latlng).setPopupContent( "ここは lat="+latlng.lat+", lng="+latlng.lng+" です." ).openPopup(); - var x = latlng.lat, y = latlng.lng; - var go1 = 38.891, go2 = 139.818; - var goalx = x.distanceTo(go1); - var goaly = y.distanceTo(go2); - if (goalx < 50 && goaly < 50) { + var x = L.latLng([38.853, 139.819]); + consoke.log(latlng.distanceTo(x)); + if (latlng.distanceTo(x) < 50) { alert("ゴール!"); stopGPS(); } // ★★★★★ ここまでの latlng.lat と latlng.lng を // if文などで判定して、特定の場所に近づいたら「GOAL!」と // 表示するように変えてみよ。 - } + } function onError(err) { restN = "あと"+(--nTrial)+"回試行します。"; gpsmarker.setPopupContent("捕捉失敗:"+restN).openPopup(); if (nTrial <= 0) { navigator.geolocation.clearWatch(watchId); } - } + } // STARTボタンに開始を仕込む document.getElementById("start").addEventListener("click", tryWatchGPS); // STOPボタンに停止を仕込む