diff --git a/map/gps/tsuruoka.js b/map/gps/tsuruoka.js new file mode 100644 index 0000000..619ceee --- /dev/null +++ b/map/gps/tsuruoka.js @@ -0,0 +1,110 @@ +document.addEventListener("DOMContentLoaded", () => { + var mymap = L.map("mymap").setView([38.891, 139.824], 16); + L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: + '© OpenStreetMap \ + contributors' + }).addTo(mymap); + + var gpsmarker = L.marker(mymap.getCenter()).addTo(mymap); + + var nTrial = 10; + var watchId = null; + function stopGPS() { + console.log("watchId="+watchId); + if (watchId != null) { + navigator.geolocation.clearWatch(watchId); + gpsmarker.setPopupContent("停めました"); + } + watchId = null; + } + function tryWatchGPS() { + stopGPS(); + watchId = navigator.geolocation.watchPosition( + onSuccess, onError,{ + maximumAge: 0, timeout: 3000, enableHighAccuracy: true}); + } + function onSuccess(pos) { + var latlng = L.latLng([pos.coords.latitude, pos.coords.longitude]); + mymap.panTo(latlng); + console.log(latlng); + var x = latlng.lat, y = latlng.lng; + if (x > 38.71096 && x < 38.71114 && y > 139.83294 && y < 139.83314) { + gpsmarker.setPopupContent("「金太郎寿し」 +鶴岡で人気のお寿司屋さんです!").openPopup(); + stopGPS(); + } else if (x > 38.71688 && x < 38.71861 && y > 139.82997 && y < 139.83039) { + gpsmarker.setPopupContent("「ミーナ」 +スーパー、ドラッグストア、CDショップなど、お店が沢山あります!").openPopup(); + stopGPS(); + } else if (x > 38.73582 && x < 38.73635 && y > 139.82956 && y < 139.83015) { + gpsmarker.setPopupContent("「八文字屋」「スターバックス」 +本屋とカフェが隣りにあって良きです!").openPopup(); + stopGPS(); + } else if (x > 38.73694 && x < 38.73700 && y > 139.80590 && y < 139.80604) { + gpsmarker.setPopupContent("「ぼんじゅーる」 +生クリームたっぷりのパフェがおすすめです!").openPopup(); + stopGPS(); + } else if (x > 38.73078 && x < 38.73086 && y > 139.84242 && y < 139.84253) { + gpsmarker.setPopupContent("「MILK」 +落ち着いた雰囲気のカフェです!").openPopup(); + stopGPS(); + } else if (x > 38.73409 && x < 38.73421 && y > 139.82974 && y < 139.82987) { + gpsmarker.setPopupContent("「肉屋食堂」 +お肉好きな人におすすめです!").openPopup(); + stopGPS(); + } else if (x > 38.72850 && x < 38.72864 && y > 139.82677 && y < 139.82694) { + gpsmarker.setPopupContent("「肉菜バルNiGoo」 +お肉好きな人におすすめです!").openPopup(); + stopGPS(); + } else if (x > 38.71953 && x < 38.71958 && y > 139.83103 && y < 139.83109) { + gpsmarker.setPopupCOntent("「長者」 +焼肉ラーメンがおすすめです!").openPoupup(); + stopGPS(); + } + + var sushi = L.latLng([38.711039, 139.833011]); + if (50 < latlng.distanceTo(sushi) < 100) { + alert("近くに人気のお寿司屋さんがあります!"); + } + var mina = L.latLng({38.717428, 139.830645]); + if (50 < latlng.distanceTo(mina) < 100) { + alert("近くにミーナがあります!"); + } + var bookcafe = L.latLng([38.736026, 139.829962]); + if (50 < latlng.distanceTo(bookcafe) < 100) { + alert("近くに本屋とスタバがあります!"); + } + var bonju = L.latLng([38.73697, 139.805979]); + if (50 < latlng.distanceTo(bonju) <100) { + alert("近くにカフェがあります!"); + } + + var milk = L.latLng([38.730821, 139.842474]); + if (50 < latlng.distanceTo(milk) < 100) { + alert("近くにカフェがあります!"); + } + var nikuya = L.latLng([38.734121, 139.830198]); + if (50 < latlng.distanceTo(nikuya) < 100) { + alert("近くにお肉が美味しい定食屋があります!"); + } + var nigoo = L.latLng([38.728572, 139.826871]); + if (50 < latlng.distanceTo(nigoo) < 100) { + alert("近くにお肉が美味しいレストランがあります!"); + } + var tyoja = L.latLng([38.719548, 139.831055]); + if (50 < latlng.distanceTo(tyoja) < 100) { + alert("近くにラーメン屋があります!"); + } + } + + function onError(err) { + restN = "あと"+(--nTrial)+"回試行します。"; + gpsmarker.setPopupContent("捕捉失敗:"+restN).openPopup(); + if (nTrial <= 0) { + navigator.geolocation.clearWatch(watchId); + } + } + document.getElementById("start").addEventListener("click", tryWatchGPS); + document.getElementById("stop").addEventListener("click", stopGPS); +}, false);