네이버 지도 api v3 주소->좌표 변환해서 출력하는 예제
네이X지도 api v3
네이버는 튜토리얼이나 개발문서가 좀 가독이 불편한 경우가 있는데
(물론 필자의 개발실력이 문제이기도 하지만)
그래서 하나 만들었습니다.
주소를 좌표로 변환후 지도로 출력하는 함수
[code]
<script type="text/javascript"
src="https://openapi.map.naver.com/openapi/v3/maps.js?clientId=개발자ID&submodules=geocoder"></script>
<div id="map" style="width:100%;height:600px;"></div>
<style>
.iw_inner {padding:10px}
.iw_inner h3 {font-size: 18px; padding-bottom: 7px}
</style>
<script id="code">
//function get_pointer (해당주소,대상지도 id,title) {
function get_pointer (adress,getid,title) {
naver.maps.Service.geocode({
address: adress
}, function(status, response) {
if (status !== naver.maps.Service.Status.OK) {
//return alert('Something wrong!');
console.log('주소에러');
}
var result = response.result, // 검색 결과의 컨테이너
items = result.items; // 검색 결과의 배열
// do Something
var x = eval(items[0].point.x);
var y = eval(items[0].point.y);
var HOME_PATH = window.HOME_PATH || '.';
var cityhall = new naver.maps.LatLng(y, x),
map = new naver.maps.Map('map', {
center: cityhall.destinationPoint(0, 500),
zoom: 10
}),
marker = new naver.maps.Marker({
map: map,
position: cityhall
});
var contentString = [
'<div class="iw_inner">',
' <h3>'+title+'</h3>',
' <p>'+adress+'</p>',
'</div>'
].join('');
var infowindow = new naver.maps.InfoWindow({
content: contentString
});
naver.maps.Event.addListener(marker, "click", function(e) {
if (infowindow.getMap()) {
infowindow.close();
} else {
infowindow.open(map, marker);
}
});
infowindow.open(map, marker);
});
}
/* 마커중복 사용안됨 */
get_pointer('대전 중구','map','대전본점');
</script>
[/code]
소스상에서 api키만 변경해주시고 사용하시면 됩니다
get_pointer('대전 중구','map','대전본점');
함수로 호출하시고 인자값은 순서대로 검색주소 반환할 div id값 마커에 표시할 이름 입니다.
댓글 5개
저같은 초짜 프로그래머는 알기 힘들게 만들어놔서 ㅡ.ㅜ
살짝 정리해본겁니다.
게시글 목록
| 번호 | 제목 |
|---|---|
| 16329 |
node.js
Node.js MongoDB 정렬
|
| 16328 |
node.js
정규 표현식으로 필터링
|
| 16327 |
node.js
환경설정 - dotenv
|
| 16326 |
node.js
Node.js MongoDB 쿼리
|
| 16325 | |
| 16324 |
node.js
nodejs MongoDB Find All
|
| 16323 |
node.js
Node.js MongoDB find
|
| 16322 |
node.js
node.js MongoDB _id Field
|
| 16321 |
node.js
node.js MongoDB 여러 문서 삽입
|
| 16320 |
node.js
Node.js MongoDB Insert
|
| 16319 |
node.js
Node.js MongoDB 컬렉션 만들기
|
| 16318 |
node.js
Node.js MongoDB 데이터베이스 생성
|
| 16317 |
node.js
Node.js MongoDB 설치
1
|
| 16316 |
node.js
Node.js 전자 메일 보내기
|
| 16315 |
node.js
Node.js 파일 업로드
|
| 16310 |
node.js
node.js 이벤트 모듈
|
| 16309 |
node.js
node.js NPM
|
| 16308 |
node.js
node.js 파일삭제, 파일 이름 바꾸기
|
| 16305 |
node.js
nodejs 기초문법 - 클래스
3
|
| 16304 |
node.js
nodejs 기초문법 - 조건문 반복문
|
| 16303 |
node.js
nodejs .기초문법 변수선언 , 함수선언
|
| 16302 |
node.js
nodejs 파일 업데이트
|
| 16301 |
node.js
nodejs 파일 만들기
|
| 16300 |
node.js
nodejs 파일 읽기
1
|
| 16299 |
node.js
Node.js 쿼리 문자열 읽기 , 쿼리 문자열 분할하기
|
| 16298 |
node.js
NOde.js HTTP 모듈
|
| 16297 |
node.js
Node.js 모듈
|
| 16295 |
node.js
nods.js 시작하기
|
| 16294 |
node.js
node.js 란 2번째
|
| 16293 |
node.js
Node.js란
1
|
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기