COMING SOON 🚀

s

네이버 지도 주소에서 간단히 사이트에 구현하기

· 13년 전 · 4058
네이버 지도 오픈 API를 통해서 간단히 만들어서 사이트에 적용시켜 보았습니다.
귀찮아서 간단히 만들어 보았습니다.

php 파일 -------

define(NAVER_MAP_KEY, "네이버오픈API에서 받은 키를 넣어주세요.");

function get_navermap_coods($p_str_addr="")
{
$int_x = 0;
$int_y = 0;

$str_addr = str_replace(" ", "", $p_str_addr);

// curl 이용해서 지도에 필요한 좌표를 취득
$dest_url = "http://openapi.map.naver.com/api/geocode.php?key=" . NAVER_MAP_KEY . "&encoding=utf-8&coord=LatLng&query=" . urlencode($str_addr);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $dest_url);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$str_result = curl_exec($ch);
curl_close($ch);

$obj_xml = simplexml_load_string($str_result);

$int_x = $obj_xml->item->point->x;
$int_y = $obj_xml->item->point->y;

return array($int_x, $int_y);
}


// 주소에서 좌표를 추출한다.
$str_addr = "서울시 강동구 길동 96-4";
list($int_x, $int_y) = get_navermap_coods($str_addr);


html 파일 --------------------------

<!-- 네이버 지도 스크립트는 상단에 위치하면 된다.-->

<script type="text/javascript">
try {document.execCommand('BackgroundImageCache', false, true);} catch(e) {}
</script>
<script type="text/javascript" src="http://openapi.map.naver.com/openapi/naverMap.naver?ver=2.0&key=<?= NAVER_MAP_KEY; ?>"></script>



<!-- 네이버 지도는 필요한 곳에 붙여넣으면 됩니다. -->

<div id = "naverMap" style="border:1px solid #000; width:431px; height:288px; margin:20px;"></div>

<script type="text/javascript">
var oPoint = new nhn.api.map.LatLng(<?= $int_y; ?>, <?= $int_x; ?>); // - 지도의 중심점을 나타내는 변수 선언
nhn.api.map.setDefaultPoint('LatLng'); // - 지도에서 기본적으로 사용하는 좌표계를 설정합니다.
var markerCount = 0;
oMap = new nhn.api.map.Map('naverMap', {
point : oPoint,
zoom : 10, // - 초기 줌 레벨은 10으로 둔다.
enableWheelZoom : false,
enableDragPan : true,
enableDblClickZoom : false,
mapMode : 0,
activateTrafficMap : false,
activateBicycleMap : false,
minMaxLevel : [ 1, 14 ],
size : new nhn.api.map.Size(431, 288)
});
var mapZoom = new nhn.api.map.ZoomControl(); // - 줌 컨트롤 선언
themeMapButton = new nhn.api.map.ThemeMapBtn(); // - 자전거지도 버튼 선언
mapTypeChangeButton = new nhn.api.map.MapTypeBtn(); // - 지도 타입 버튼 선언
var trafficButton = new nhn.api.map.TrafficMapBtn(); // - 실시간 교통지도 버튼 선언
trafficButton.setPosition({top:10, right:110}); // - 실시간 교통지도 버튼 위치 지정
mapTypeChangeButton.setPosition({top:10, left:50}); // - 지도 타입 버튼 위치 지정
themeMapButton.setPosition({top:10, right:10}); // - 자전거지도 버튼 위치 지정
mapZoom.setPosition({left:10, top:10}); // - 줌 컨트롤 위치 지정.
oMap.addControl(mapZoom);
oMap.addControl(themeMapButton);
oMap.addControl(mapTypeChangeButton);
oMap.addControl(trafficButton);

var oSize = new nhn.api.map.Size(28, 37);
var oOffset = new nhn.api.map.Size(14, 37);
var oIcon = new nhn.api.map.Icon('http://static.naver.com/maps2/icons/pin_spot2.png', oSize, oOffset);

var oMarker = new nhn.api.map.Marker(oIcon, { title : '<?= $str_hospital_name; ?>' }); //마커 생성
oMarker.setPoint(oPoint);
oMap.addOverlay(oMarker);
var oLabel = new nhn.api.map.MarkerLabel(); // - 마커 라벨 선언.
oMap.addOverlay(oLabel); // - 마커 라벨 지도에 추가. 기본은 라벨이 보이지 않는 상태로 추가됨.
oLabel.setVisible(true, oMarker); // 마커 라벨 보이기

</script>

<!-- 네이버 지도 끝 -->
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
12년 전 조회 1만
12년 전 조회 2,309
12년 전 조회 2,261
12년 전 조회 2,710
12년 전 조회 2,177
12년 전 조회 2,328
12년 전 조회 4,593
12년 전 조회 2,547
12년 전 조회 3,202
12년 전 조회 2,204
12년 전 조회 2,368
12년 전 조회 4,095
12년 전 조회 1,929
12년 전 조회 2,424
12년 전 조회 2,743
12년 전 조회 3,192
12년 전 조회 3,285
12년 전 조회 3,762
12년 전 조회 2,197
12년 전 조회 2,220
12년 전 조회 5,603
12년 전 조회 2,664
12년 전 조회 2,840
12년 전 조회 6,686
12년 전 조회 4,408
12년 전 조회 3,328
13년 전 조회 2,509
13년 전 조회 4,681
13년 전 조회 3,677
13년 전 조회 3,375
13년 전 조회 3,024
13년 전 조회 2,718
13년 전 조회 2,712
13년 전 조회 2,459
13년 전 조회 3,563
13년 전 조회 2,871
13년 전 조회 2,525
13년 전 조회 3,593
13년 전 조회 2,792
13년 전 조회 3,397
13년 전 조회 4,619
13년 전 조회 2,388
13년 전 조회 3,385
13년 전 조회 2,206
13년 전 조회 2,680
13년 전 조회 3,309
13년 전 조회 2,951
13년 전 조회 5,735
13년 전 조회 3,861
13년 전 조회 4,059
13년 전 조회 2,397
13년 전 조회 9,718
13년 전 조회 4,562
13년 전 조회 2,620
13년 전 조회 2,484
13년 전 조회 3,882
13년 전 조회 6,598
13년 전 조회 4,607
13년 전 조회 2,531
13년 전 조회 1.5만
13년 전 조회 2,406
13년 전 조회 1,822
13년 전 조회 5,126
13년 전 조회 2,616
13년 전 조회 1.1만
13년 전 조회 2,009
13년 전 조회 2,437
13년 전 조회 4,457
13년 전 조회 2,058
13년 전 조회 2,958
13년 전 조회 4,900
13년 전 조회 2,269
13년 전 조회 2,181
13년 전 조회 6,545
13년 전 조회 2,643
13년 전 조회 1,967
13년 전 조회 3,717
13년 전 조회 3,732
13년 전 조회 2,684
13년 전 조회 4,132
13년 전 조회 7,804
13년 전 조회 3,382
13년 전 조회 1,955
13년 전 조회 3,120
13년 전 조회 3,061
13년 전 조회 3,851
13년 전 조회 1,820
13년 전 조회 2,919
13년 전 조회 1,968
13년 전 조회 3,003
13년 전 조회 3,910
13년 전 조회 2,400
13년 전 조회 5,103
13년 전 조회 1.1만
13년 전 조회 2,373
13년 전 조회 3,712
13년 전 조회 3,337
13년 전 조회 4,202
13년 전 조회 7,249
13년 전 조회 3,841