작성
·
22
0
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>맛집지도</title>
<meta name="author" content="동네코딩" />
<meta name="description" content="맛집지도 서비스" />
<meta
name="keywords"
content="동네코딩, 맛집지도, 유튜버맛집, 맛집유튜버"
/>
<link rel="stylesheet" href="style.css" />
</head>
<body>
<nav>
<div class="inner">
<div class="nav-container">
<h1 class="nav-title">맛집지도</h1>
<button class="nav-contact">Contact</button>
</div>
</div>
</nav>
<main>
<section id="category">
<div class="inner">
<div class="category-container">
<h2 class="category-title">맛집지도 카테고리를 선택해보세요</h2>
<div class="category-list">
<button class="category-item">한식</button>
<button class="category-item">중식</button>
<button class="category-item">일식</button>
<button class="category-item">양식</button>
<button class="category-item">분식</button>
<button class="category-item">구이</button>
<button class="category-item">회/초밥</button>
<button class="category-item">기타</button>
</div>
</div>
</div>
</section>
<!--카테고리-->
<div class="inner"></div>
<div id="map" style="width: 500px; height: 400px;"></div>
<!--카카오지도-->
</main>
<script
type="text/javascript"
src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=0424fde511a7594cc79f908810e62e4f"></script>
<script src="script.js" defer></script>
</body>
</html>
@font-face {
font-family: "KyoboHandwriting2020A";
src: url("https://cdn.jsdelivr.net/gh/projectnoonnu/noonfonts_2112@1.0/KyoboHandwriting2020A.woff")
format("woff");
font-weight: normal;
font-style: normal;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
html {
font-size: 10px;
font-family: "KyoboHandwriting2020A";
}
nav {
/*background-color: #e69a06;*/
}
.nav-container {
padding: 1rem 0;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
}
.nav-title{
font-size: 3rem;
}
.nav-contact {
font-size: 2.5rem;
border: 0;
background: none;
cursor: pointer;
font-family: inherit;
}
.category-title{
font-size: 3.5rem;
}
.category-item {
width: 25%;
height: 5rem;
background: none;
border: none;
font-family: inherit;
font-size: 1.6rem;
}
.category-item:hover{
color:#e69a06;
cursor:pointer;
}
.inner{
padding: 0 1.5rem;
}
@media all and (min-width: 1024px) {
.inner {
max-width: 1024px;
margin: 0 auto;
}
}
/* 카카오맵 CSS */
body{
height: 100vh;
}
nav{
height: 59px;
}
main{
padding-top: 1.5rem;
height: calc(100% -59px);
display:flex;
flex-direction: column;
}
#map{
flex-wrap: 1;
width: 100%;
height: 100px;
}
window.onload = function () {
var container = document.getElementById('map');
var options = {
center: new kakao.maps.LatLng(33.450701, 126.570667),
level: 3
};
var map = new kakao.maps.Map(container, options);
};
이렇게 작성했는데 live server 해보니 이런 오류뜨면서 지도가 아예 안 뜨네요ㅠㅠ
답변 1
0
안녕하세요, 인프런 AI 인턴입니다.
임채연님, 카카오 지도 API를 사용하실 때 “Uncaught ReferenceError: kakao is not defined” 오류가 발생하는 것은 일반적으로 스크립트 로드 순서나 API 키의 문제일 수 있습니다.
다음 해결 방법을 시도해 보세요:
API 키 확인: 카카오 지도 API 키가 올바르게 발급되었는지 확인하세요. 만일 현재 사용 중인 appkey
가 유효하지 않다면, 카카오 디벨로퍼스에서 새로운 API 키를 생성해서 사용해 보세요.
스크립트 로딩 순서:
<script></script>
태그로 로드하고 있는데, 이 때 defer
속성을 추가하지 않아서 DOM이 로드되기 전에 스크립트가 불러와지기 때문에 kakao 객체가 정의되지 않는 문제가 발생할 수 있습니다.<script>
태그의 src
에 defer
혹은 async
속성을 추가해 보세요.<script
type="text/javascript"
src="https://dapi.kakao.com/v2/maps/sdk.js?appkey=0424fde511a7594cc79f908810e62e4f"
defer></script>
개발자 도구 콘솔 확인: 추가적인 오류 메시지가 있는지 브라우저의 개발자 도구 콘솔을 확인하세요. 추가적인 정보가 문제 해결에 도움이 될 수 있습니다.
위 방법으로도 문제를 해결할 수 없다면, API 키 발급과 API 호출 권한을 다시 한번 확인해 보세요. 문제를 계속해서 겪으신다면, 문의를 통해 보다 상세한 도움을 받을 수 있습니다.
출처: 카카오 개발자 페이지