diff --git a/map/gps/quizu.js b/map/gps/quizu.js index 7898192..4aed713 100644 --- a/map/gps/quizu.js +++ b/map/gps/quizu.js @@ -1 +1,127 @@ -a +document.addEventListener("DOMContentLoaded", () => { + var mymap = L.map("gpsmap").setView([38.891, 139.824], 16); + L.tileLayer('https://{s}.tile.osm.org/{z}/{x}/{y}.png', { + attribution: + '© OpenStreetMap \ + contributors' + }).addTo(mymap); + + var image1 = "

?????

"; + var popup1 = L.popup({ maxWidth: 450 }).setContent(image1); + let a = L.marker([38.879230,139.847138]).bindPopup(popup1).addTo(mymap); + a = L.latLng(38.892325, 139.819474); + +? var image2 = "

?????

"; + var popup2 = L.popup({ maxWidth: 450 }).setContent(image2); + let b = L.marker([38.893690, 139.819490]).bindPopup(popup2).addTo(mymap); + b = L.latLng(38.893690, 139.819490); + + var image3 = "

???

"; + var popup3 = L.popup({ maxWidth: 450 }).setContent(image3); + let c = L.marker([38.892972, 139.818900]).bindPopup(popup3).addTo(mymap); + c = L.latLng(38.892972, 139.818900); + + var image4 = "

???

"; + var popup4 = L.popup({ maxWidth: 450 }).setContent(image4); + let d = L.marker([38.894329, 139.819570]).bindPopup(popup4).addTo(mymap); + d = L.latLng(38.894329, 139.819570); + + var gpsmarker = L.marker(mymap.getCenter()).addTo(mymap); + gpsmarker.bindPopup("START????").openPopup(); + + var nTrial = 100 + var watchId = null; // ???null????? + function stopGPS() { // watch??????????null??? + console.log("watchId="+watchId); + if (watchId != null) { // null?????????????(???0) + navigator.geolocation.clearWatch(watchId); + document.getElementById("title").textContent = "stop"; + gpsmarker.setPopupContent("?????"); + } + watchId = null; + } + function tryWatchGPS() { + stopGPS(); // ?????????????? + watchId = navigator.geolocation.watchPosition( + onSuccess, onError,{ + maximumAge: 0, timeout: 3000, enableHighAccuracy: true}); + document.getElementById("title").textContent = "START!!"; + } + function onSuccess(pos) { // GPS???????????? + var latlng = L.latLng([pos.coords.latitude, pos.coords.longitude]); + mymap.panTo(latlng);// ??????????? + console.log(latlng); + // ????? ???? + gpsmarker.setLatLng(latlng).setPopupContent( + "??? lat="+latlng.lat+", lng="+latlng.lng+" ??." + ).openPopup(); + var qs1 = "

?????

????

"; + var popup1 = L.popup({ maxWidth: 450 }).setContent(qs1); + var x = latlng.lat, y = latlng.lng; + var latlng1 = L.latLng([38.879232, 139.853824]); + var latlng2 = L.latLng([38.893690, 139.819490]); + var latlng3 = L.latLng([38.892972, 139.818900]); + var latlng4 = L.latLng([38.894329, 139.819570]); + //console.log(latlng.distanceTo(latlng2)); + + if(latlng.distanceTo(latlng1) < 50){ + alert("????!???????m??????"); + stopGPS(); + + }else if (latlng.distanceTo(latlng2) < 50){ + alert("????!????????????????????(????????????)"); + stopGPS(); + + }else if (latlng.distanceTo(latlng3) < 50){ + alert("????!????????????????????"); + stopGPS(); + + }else if(latlng.distanceTo(latlng4) < 50){ + alert("????!???????m??????"); + stopGPS(); + } + } + + function checkButton(){ + answer = document.getElementById( "mytext" ).value ; + //msg.innerText = '??????' + if(38.879230,139.847138){ + if(answer == 2236){ + alert("????"); + }else{ + alert("?????"); + } + }else if(38.893690, 139.819490){ + if(answer == 2001){ + alert("????"); + }else{ + alert("?????"); + } + }else if(38.892972, 139.818900){ + if(answer == ?){ + alert("????"); + }else{ + alert("?????"); + } + }else if(38.894329, 139.819570){ + if(answer == 1643){ + alert("????"); + }else{ + alert("?????"); + } + } + } + + function onError(err) { + restN = "??"+(--nTrial)+"???????"; + gpsmarker.setPopupContent("????:"+restN).openPopup(); + if (nTrial <= 0) { + navigator.geolocation.clearWatch(watchId); + } + } + document.getElementById("checkButton").addEventListener("click", checkButton); + // START?????????? + document.getElementById("start").addEventListener("click", tryWatchGPS); + // STOP?????????? + document.getElementById("stop").addEventListener("click", stopGPS); +}, false);