<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>
Google地图标注(最新版V3下的写法)基础篇
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:http://www.heiqu.com/a9b188db63373ec11b039a0464c0a369.html