Search

์นด์นด์˜ค๋งต ์‹œ์ž‘ํ•˜๊ธฐ

์นด์นด์˜ค๋งต ์‹œ์ž‘ํ•˜๊ธฐ

Wizard

: ์ง€๋„ Web API์˜ ์ฃผ์š” ๊ธฐ๋Šฅ์— ๋Œ€ํ•œ ์ฝ”๋“œ๋ฅผ ์ž๋™์œผ๋กœ ์ƒ์„ฑํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
์—ฌ๊ธฐ์„œ API ๊ธฐ๋Šฅ์„ ๋ฐ”๋กœ ์‚ฌ์šฉํ•ด๋ณด๊ณ , ํ•ด๋‹น ๊ธฐ๋Šฅ์ด ํฌํ•จ๋˜ HTML+JS ์ฝ”๋“œ๋ฅผ ๋ณต์‚ฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‹œ์ž‘์ฝ”๋“œ

<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>๋‹ค์Œ ์ง€๋„ API</title> </head> <body> <div id="map" style="width:750px;height:350px;"></div> <p id="position"></p> <script src="//dapi.kakao.com/v2/maps/sdk.js?appkey=๋ฐœ๊ธ‰๋ฐ›์€ APP KEY๋ฅผ ์‚ฌ์šฉํ•˜์„ธ์š”"></script> <script> var mapContainer = document.getElementById('map'), // ์ง€๋„๋ฅผ ํ‘œ์‹œํ•  div mapOption = { center: new kakao.maps.LatLng(37.56838, 126.97838), // ์ง€๋„์˜ ์ค‘์‹ฌ์ขŒํ‘œ level: 4, // ์ง€๋„์˜ ํ™•๋Œ€ ๋ ˆ๋ฒจ mapTypeId : kakao.maps.MapTypeId.ROADMAP // ์ง€๋„์ข…๋ฅ˜ }; // ์ง€๋„๋ฅผ ์ƒ์„ฑํ•œ๋‹ค var map = new kakao.maps.Map(mapContainer, mapOption); // ์ง€๋„์— ๋งˆ์ปค๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ํ‘œ์‹œํ•œ๋‹ค var marker = new kakao.maps.Marker({ position: new kakao.maps.LatLng(37.56838, 126.97838), // ๋งˆ์ปค์˜ ์ขŒํ‘œ map: map // ๋งˆ์ปค๋ฅผ ํ‘œ์‹œํ•  ์ง€๋„ ๊ฐ์ฒด }); // ์ง€๋„ ํด๋ฆญ ์ด๋ฒคํŠธ๋ฅผ ๋“ฑ๋กํ•œ๋‹ค (์ขŒํด๋ฆญ : click, ์šฐํด๋ฆญ : rightclick, ๋”๋ธ”ํด๋ฆญ : dblclick) kakao.maps.event.addListener(map, 'click', function (mouseEvent) { console.log('์ง€๋„์—์„œ ํด๋ฆญํ•œ ์œ„์น˜์˜ ์ขŒํ‘œ๋Š” ' + mouseEvent.latLng.toString() + ' ์ž…๋‹ˆ๋‹ค.'); let position = document.getElementById('position') // ์œ„๋„,๊ฒฝ๋„ ์ •๋ณด let latlng = mouseEvent.latLng let lat = latlng.getLat() // ์œ„๋„ let lng = latlng.getLng() // ๊ฒฝ๋„ let msg = `์œ„๋„ : ${lat}, ๊ฒฝ๋„ : ${lng}` position.innerHTML = msg }); // ์ปค์Šคํ…€ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  ์ง€๋„์— ํ‘œ์‹œํ•œ๋‹ค var customOverlay = new kakao.maps.CustomOverlay({ map: map, content: '<div style="padding:0 5px;background:#fff;">HTML์ฝ”๋“œ๋ฅผ ์ž…๋ ฅํ•ด์ฃผ์„ธ์š” :D</div>', position: new kakao.maps.LatLng(37.56838, 126.97838), // ์ปค์Šคํ…€ ์˜ค๋ฒ„๋ ˆ์ด๋ฅผ ํ‘œ์‹œํ•  ์ขŒํ‘œ xAnchor: 0.5, // ์ปจํ…์ธ ์˜ x ์œ„์น˜ yAnchor: 0 // ์ปจํ…์ธ ์˜ y ์œ„์น˜ }); </script> </body> </html>
HTML
๋ณต์‚ฌ