-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrontend.js
39 lines (34 loc) ยท 1.57 KB
/
frontend.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
document.addEventListener("DOMContentLoaded", function () {
// ์นด์นด์ค๋งต ์ด๊ธฐํ
var container = document.getElementById('map');
var options = {
center: new kakao.maps.LatLng(35.14152416269298, 126.9312745478554), // ์ด๊ธฐ ์์น:์ค์๋์๊ด
level: 4
};
var map = new kakao.maps.Map(container, options);
// ๋ฒ์ค ๋ง์ปค ์์ฑ
var busMarker = new kakao.maps.Marker({
position: new kakao.maps.LatLng(35.141939023044976, 126.92780114915257), // ์ด๊ธฐ ์์น ์ค์
image: new kakao.maps.MarkerImage('/0_capstone/๊ทธ๋ฆผ2.svg', new kakao.maps.Size(20, 40)),
});
// ๋ง์ปค ์ง๋์ ํ์
busMarker.setMap(map);
// ์๋์ ๊ฒฝ๋๋ฅผ ์ถ๋ ฅํ div ์๋ฆฌ๋จผํธ
var locationInfoDiv = document.getElementById('location-info');
// ์๋ฒ๋ก๋ถํฐ ์์น ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์์ ๋ง์ปค ์ด๋
function updateBusLocation() {
// ์๋ฒ๋ก๋ถํฐ ์์น ๋ฐ์ดํฐ๋ฅผ ๋ฐ์์ค๋ Ajax ์์ฒญ
// ์๋ฒ์์๋ ํ์ํ ๋ฐ์ดํฐ๋ฅผ JSON ํ์์ผ๋ก ์๋ตํด์ผ ํจ
fetch('http://13.125.227.53/Logtest.php') // php ๋งํฌ ๋ฃ๊ธฐ
.then(response => response.json())
.then(data => {
// ์๋์ ๊ฒฝ๋๋ฅผ ์ถ๋ ฅ
locationInfoDiv.innerHTML = 'ํ์ฌ ์์น : ์๋: ' + data.lat + ', ๊ฒฝ๋: ' + data.lon;
// ๋ฐ์์จ ์์น๋ก ๋ง์ปค ์ด๋
busMarker.setPosition(new kakao.maps.LatLng(data.lat, data.lon));
})
.catch(error => console.error('Error:', error));
}
// 0.8์ด ๊ฐ๊ฒฉ์ผ๋ก ์์น ์
๋ฐ์ดํธ
setInterval(updateBusLocation, 800);
});