Google API 구글맵 마커 + 말풍선 - v2
Open API/Google2016. 11. 18. 12:11
반응형
Google API를 이용한 구글맵 마커(Marker) 표시 및 말풍선(infowindow) 기본 샘플 코드입니다.
Test Url : http://www.uhoon.co.kr/test/63.html
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title> Google map </title> </head> <body onload="onLoad();"> <script src="http://maps.google.com/maps?file=api&v=2&hl=en&key=" type="text/javascript"></script> <script type="text/javascript"> var gmarkers = []; var htmls = []; // global "map" variable var map; // This function picks up the side_bar click and opens the corresponding info window function myclick(i) { gmarkers[i].openInfoWindowHtml(htmls[i]); } // This function zooms in or out // its not necessary to check for out of range zoom numbers, because the API checks function myzoom(a) { map.setZoom(map.getZoom() + a); } function onLoad() { if (GBrowserIsCompatible()) { // this variable will collect the html which will eventualkly be placed in the side_bar var side_bar_html = ""; var i = 0; var baseIcon = new GIcon(); baseIcon.iconSize=new GSize(15,24); baseIcon.shadowSize=new GSize(24,24); baseIcon.iconAnchor=new GPoint(0,12); baseIcon.infoWindowAnchor=new GPoint(12,0); var martini = new GIcon(baseIcon, "http://labs.google.com/ridefinder/images/mm_20_gray.png", null); //var martini = new GIcon(baseIcon, "/img/hotel/check.png", null, "/img/hotel/check.png"); function createMarker(point,html,icon) { var marker = new GMarker(point,icon); GEvent.addListener(marker, "click", function() { marker.openInfoWindowHtml(html); }); return marker; } // create the map using the global "map" variable map = new GMap2(document.getElementById("map")); map.addControl(new GOverviewMapControl()); map.addControl(new GLargeMapControl()); map.addControl(new GMapTypeControl()); map.addControl(new GScaleControl()); map.enableDoubleClickZoom(); map.setCenter(new GLatLng(37.55544,127.07590), 15, G_NORMAL_MAP); //Map Type : G_NORMAL_MAP, G_SATELLITE_MAP, G_HYBRID_MAP by Ribbie // add the points var point = new GLatLng(37.55544,127.07590); var marker = createMarker(point,"<div align='left' style='font-size:12px;width:300px;'>군자동 주민센터</div>",martini) map.addOverlay(marker); } else { alert("Sorry, the Google Maps API is not compatible with this browser"); } } // end of onLoad function </script> <div id="map" style="width:450px; height: 300px" ></div> </body> </html>
댓글()