|
|
<?php
define('MAPKEY', 'YOURMAPKEY'); define('NAVERKEY', 'YOURNAVERKEY'); $names = ""; $addresses = ""; $mapWidth = 640; $mapHeight = 480; $zoom = 11; $x = 500000; $y = 500000; $markerX = -1; $markerY = -1; $query = null; if (array_key_exists("query", $_GET)) { $query = trim($_GET["query"]); if(strlen($query) > 0){ $encodedquery = urlencode($query); $url = "http://openapi.naver.com/search?query=$encodedquery&target=local&sort=vote&key=".NAVERKEY; $name = simplexml_load_file($url)->channel; foreach($name->item as $item) { $names .= makeItem($item->title, $item->mapx, $item->mapy); } $encodedquery = urlencode(iconv('utf-8', 'euc-kr', $query)); $url2 = "http://maps.naver.com/api/geocode.php?query=$encodedquery&key=".MAPKEY; $address = simplexml_load_file($url2); foreach($address->item as $item) { $point = $item->point; $addresses .= makeItem($item->address, $point->x, $point->y); } } // endif } // endif if (array_key_exists("mapWidth", $_GET)) { $mapWidth = trim($_GET["mapWidth"]); $mapHeight = trim($_GET["mapHeight"]); $zoom = trim($_GET["zoom"]); $x = trim($_GET["x"]); $y = trim($_GET["y"]); $markerX = trim($_GET["markerX"]); $markerY = trim($_GET["markerY"]); } function makeItem($title, $mapx, $mapy) { return "<a href='#' onclick='javascript } ?> <html> <head> <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/> <meta http-equiv="Cache-Control" content="No-Cache"/> <meta http-equiv="Pragma" content="No-Cache"/> <title>sketch map</title> </head> <body style="margin:0px 0px 0px 0px"> <div id="mapContainer" style="width:<?echo $mapWidth?>; height:<?echo $mapHeight?>"></div> <div id="mapapi"> <script type="text/JavaScript" src="http://maps.naver.com/js/naverMap.naver?key=YOURMAPKEY"></script> </div> <script type="text/JavaScript"> var markerUrl = 'http://sstatic.naver.com/search/local/icon3/icos_LA.gif'; function newMarker(x, y) { if (x < 0 || y < 0) { return null; } var icon = new NIcon(markerUrl, new NSize(15, 14)); var newMarker = new NMark(new NPoint(x, y), icon); mapObj.addOverlay(newMarker); return newMarker; } function genHtml() { var code = "mapObj.setCenterAndZoom(new NPoint(" + mapObj.getCenter() + "), " + mapObj.getZoom() + "); "; if (marker) { var point = marker.getPoint(); code += "var pos = new NPoint(" + point.getX() + ", " + point.getY() + "); " + "marker = new NMark(pos, new NIcon('" + markerUrl + "', new NSize(15, 14))); " + "mapObj.addOverlay(marker);"; } mapStyle = document.getElementById('mapContainer').style; res = document.createTextNode( '<div id="mapContainer" style="width:' + mapStyle.width + '; height:' + mapStyle.height + '";></div>' + document.getElementById('mapapi').innerHTML + '<script type="text/JavaScript">' + document.getElementById('script').innerHTML + code + ' </script>'); textarea = document.getElementById('result') child = textarea.childNodes[0]; if (child) { textarea.replaceChild(res, child); } else { textarea.appendChild(res); } } function addHiddens(form, dict) { for (name in dict) { hidden = document.createElement('input'); hidden.type = 'hidden'; hidden.name = name; hidden.value = dict[name]; form.appendChild(hidden); } } function addCommons(form) { var center = mapObj.getCenter(); var point = marker.getPoint(); addHiddens(form, {'zoom': mapObj.getZoom(), 'x': center.getX(), 'y': center.getY(), 'markerX': point.getX(), 'markerY': point.getY()}); } function find(form) { addCommons(form); addHiddens(form, {'mapWidth': <?echo $mapWidth?>, 'mapHeight': <?echo $mapHeight?>}); } function clickMap(pos) { if (marker) { marker.setPoint(pos); } else { marker = newMarker(pos.getX(), pos.getY()); } } </script> <div> <form id="resize" method="get" action="sketchmap.php" onsubmit="javascript size <input type="text" name="mapWidth" value="<?echo $mapWidth?>" style="width: 40;"> <input type="text" name="mapHeight" value="<?echo $mapHeight?>" style="width: 40;"> <input type="submit" value="resize"> </form> <form id="search" method="get" action="sketchmap.php" onsubmit="javascript addr <input type="text" name="query"> <input type="submit" value="search"> </form> </div> <div> <?php echo $names; echo $addresses; ?> </div> <input type="button" value="html" onclick="javascript <textarea name="result" style="width: 400; height: 300;" id="result"> </textarea> <script type="text/JavaScript" id="script"> var mapObj = new NMap(document.getElementById('mapContainer')); var zoom = new NZoomControl(); zoom.setAlign("right"); zoom.setValign("bottom"); mapObj.addControl(zoom); </script> <script type="text/JavaScript"> NEvent.addListener(mapObj, "click", clickMap); var marker = newMarker(<?echo $markerX?>, <?echo $markerY?>); mapObj.setZoom(<?echo $zoom?>); mapObj.setCenter(new NPoint(<?echo $x?>, <?echo $y?>)); </script> </body> </html> [출처] [강좌] 약도 예제 (네이버 OpenAPI 공식 카페) |작성자 openapi |
|
|
Home
Member Infor


전체 방문 : 1,407,336
전체 본문글 : 2,738
ArticleRead.nhn%3Farticleid=1075



















