JavaScript 네이버 지도 API 3.0 활용 멀티맵 만들기
페이지 정보
본문
샘플보기 : https://www.happyjung.com/demo/map/naver_multi.php
Map1<br>
<div id="naverMap1"></div>
Map2<br>
<div id="naverMap2"></div>
<?php
$clientId = "NaverAPI_ClientID"; // happyjung.com API
?>
<script src="//code.jquery.com/jquery-1.12.4.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?clientId=<?php echo $clientId; ?>&submodules=geocoder"></script>
<script type="text/javascript" >
var strNaverMapKey="<?php echo $clientId; ?>";
</script>
<script>
function multi_naverMap(divID, x, y, store_name) {
var oPoint = new naver.maps.Point(37.6238066, 127.0732484);
$("#"+divID).width("100%");
$("#"+divID).height("100%");
oSize = new naver.maps.Size($("#"+divID).width(), $("#"+divID).height());
var oMap = new naver.maps.Map(divID ,{
center : oPoint,
zoom : 12,
scrollWheel : true,
draggable : true,
disableDoubleClickZoom : false,
mapTypeControl: false,
minZoom : 1,
maxZoom : 14,
size : oSize,
zoomControl : true,
zoomControlOptions : {
position: naver.maps.Position.TOP_RIGHT
}
});
var iSize = new naver.maps.Size(65, 76);
var iOffset = new naver.maps.Size(14, 37);
var viewMap = function (x, y, storename){
var oPoint = new naver.maps.Point(x, y);
var oMarker = new naver.maps.Marker({
title : storename,
position : oPoint,
icon : {
content : '<img src="http://t1.daumcdn.net/localimg/localimages/07/mapapidoc/marker_red.png">',
size : iSize,
anchor : iOffset
}
});
if(typeof oMap === 'undefined'){
setTimeout("viewMap('"+x+"','"+y+"','"+idx+"','"+storename+"')","3000");
} else {
oMarker.setMap(null);
oMap.setCenter(oPoint);
oMarker.setMap(oMap);
naver.maps.Event.addListener(oMarker, 'click', function(e) {
var oTarget = e.overlay;
oMap.setCenter(oTarget.getPosition());
});
}
};
$(window).bind('resize', function () {
$("#"+divID).width("100%");
$("#"+divID).height("100%");
oMap.setSize(new naver.maps.Size($("#"+divID).width(),$("#"+divID).height()));
});
viewMap(x, y, store_name);
}
</script>
<script>
// multi_naverMap("ID값", LatLngY, LatLngX, "설명");
multi_naverMap("naverMap1", 126.890496, 37.480894, "해피정닷컴");
multi_naverMap("naverMap2", 126.9664045, 37.5609433, "서울시청");
</script>
Map1<br>
<div id="naverMap1"></div>
Map2<br>
<div id="naverMap2"></div>
<?php
$clientId = "NaverAPI_ClientID"; // happyjung.com API
?>
<script src="//code.jquery.com/jquery-1.12.4.min.js" crossorigin="anonymous"></script>
<script type="text/javascript" src="https://openapi.map.naver.com/openapi/v3/maps.js?clientId=<?php echo $clientId; ?>&submodules=geocoder"></script>
<script type="text/javascript" >
var strNaverMapKey="<?php echo $clientId; ?>";
</script>
<script>
function multi_naverMap(divID, x, y, store_name) {
var oPoint = new naver.maps.Point(37.6238066, 127.0732484);
$("#"+divID).width("100%");
$("#"+divID).height("100%");
oSize = new naver.maps.Size($("#"+divID).width(), $("#"+divID).height());
var oMap = new naver.maps.Map(divID ,{
center : oPoint,
zoom : 12,
scrollWheel : true,
draggable : true,
disableDoubleClickZoom : false,
mapTypeControl: false,
minZoom : 1,
maxZoom : 14,
size : oSize,
zoomControl : true,
zoomControlOptions : {
position: naver.maps.Position.TOP_RIGHT
}
});
var iSize = new naver.maps.Size(65, 76);
var iOffset = new naver.maps.Size(14, 37);
var viewMap = function (x, y, storename){
var oPoint = new naver.maps.Point(x, y);
var oMarker = new naver.maps.Marker({
title : storename,
position : oPoint,
icon : {
content : '<img src="http://t1.daumcdn.net/localimg/localimages/07/mapapidoc/marker_red.png">',
size : iSize,
anchor : iOffset
}
});
if(typeof oMap === 'undefined'){
setTimeout("viewMap('"+x+"','"+y+"','"+idx+"','"+storename+"')","3000");
} else {
oMarker.setMap(null);
oMap.setCenter(oPoint);
oMarker.setMap(oMap);
naver.maps.Event.addListener(oMarker, 'click', function(e) {
var oTarget = e.overlay;
oMap.setCenter(oTarget.getPosition());
});
}
};
$(window).bind('resize', function () {
$("#"+divID).width("100%");
$("#"+divID).height("100%");
oMap.setSize(new naver.maps.Size($("#"+divID).width(),$("#"+divID).height()));
});
viewMap(x, y, store_name);
}
</script>
<script>
// multi_naverMap("ID값", LatLngY, LatLngX, "설명");
multi_naverMap("naverMap1", 126.890496, 37.480894, "해피정닷컴");
multi_naverMap("naverMap2", 126.9664045, 37.5609433, "서울시청");
</script>
댓글목록
등록된 댓글이 없습니다.