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>

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/8347.html