Google 맵 마크업 (최신 V3에서 쓰기) 기본 편

<script type="text/javascript">  
		var map;
        var markersArray = [];

       function initialize()
        {
		   if(window.top.$('#<?php echo $field?>').val()) {
		   var data = window.top.$('#<?php echo $field?>').val();
			var data = data.split('|');
			var lngX = data[0];
			var latY = data[1];
			var zoom = data[2] ? Number(data[2]) : 10;
            var latlng = new google.maps.LatLng(latY, lngX);
		   }
		   else
			{
			    var latlng = new google.maps.LatLng(41, 29);
				var zoom = 10;
			}
            var myOptions = {
                zoom: zoom,
                center: latlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP
            };
            map = new google.maps.Map(document.getElementById("mapObj"), myOptions);

            // add a click event handler to the map object
            google.maps.event.addListener(map, "click", function(event)
            {
                // place a marker
                addMarker(event.latLng);

                // display the lat/lng in your form's lat/lng fields
            });
        }
        function addMarker(location) {
            // first remove all markers if there are any
            deleteOverlays();

            var marker = new google.maps.Marker({
                position: location, 
                map: map
            });

            // add marker in markers array
            markersArray.push(marker);
			var ZoomLevel = map.getZoom();
				window.top.$('#<?php echo $field?>').val(location.lat()+'|'+location.lng()+'|'+ZoomLevel);
            //map.setCenter(location);
        }

        // Deletes all markers in the array by removing references to them
        function deleteOverlays() {
            if (markersArray) {
                for (i in markersArray) {
                    markersArray[i].setMap(null);
                }
            markersArray.length = 0;
            }
        }
google.maps.event.addDomListener(window, 'load', initialize);
    </script>

좋은 웹페이지 즐겨찾기