我正在使用以下代码生成标记引脚.它加载完美,但在这张地图的左边我有过滤器.如何在不重新加载地图的情况下重新加载标记?这已经引起了一些挫折,所以任何帮助将不胜感激.
非常感谢,
//Google map results var contentStrings = []; var infowindow = new google.maps.InfoWindow(); var mapinited = false; var map; var myOptions = { zoom: 11, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var currentinfobox; var myLatlng; var markersArray=[]; var LatLngList = []; $().ready(function() { //reinit search if (window.location.hash) { submitForm(window.location.hash.replace('#','')); } else if (readCookie('sf')) { //submitForm(readCookie('sf')); } //init map $('#map_view').click(function() { if (mapinited) { return; } else { mapinited = true; initMap(); } function initMap() { locate(["Ireland"],function(result) { map = new google.maps.Map(document.getElementById("search_map"), myOptions); myLatlng = new google.maps.LatLng(result.lat(),result.lng()); var key =0; $.each(map_results, function(key, value){ LatLngList[key] = new google.maps.LatLng(value.lat,value.long) contentStrings[key] = ''+ ' '+ ''; key++; });//end each map_results=""; google.maps.event.addListener(infowindow, 'domready', function() { var infocontent = $('#ginfo_content').clone(); var l = $('#ginfo_content').parent().parent().parent().addClass('original_popup').html(''); $('.original_popup').append(infocontent).show(); $('.original_popup').css('width','360px').css('height','230px').css('left','+=27px').css('top','+=65px'); }); var zoomChangeBoundsListener = google.maps.event.addListener(map, 'zoom_changed', function() { if (this.getZoom() > 14) // Change max/min zoom here this.setZoom(14); google.maps.event.removeListener(zoomChangeBoundsListener); }); var infoboxlistener = google.maps.event.addListener(map, 'zoom_changed', `enter code here`function() { infowindow.close(); }); loadMapInit(LatLngList,contentStrings); }); } }); });'+ ''+ ' '+ ''+ 'x'+ ''+ '
'+ ''+ ''+ ''+ 'Contact'+ ''+ ''+ ''+ value.firstname +' '+value.lastname+', '+ value.address +'
'+ ''+ stripslashes(value.about) +'
'+ '
'+ ' '+ '
alex-phillip.. 22
希望这能回答你的要求:
创建标记时,可以使用"map"参数设置其地图并显示它.或者,如果要将其绑定到过滤器,则可以忽略地图参数并稍后使用marker.setMap(map).
// To add the marker to the map, use the 'map' property var marker = new google.maps.Marker({ position: myLatlng, map: map, title:"Hello World!" });
如果要"删除"和"添加"带事件的标记,可以使用marker.setMap(null)删除标记和marker.setMap(map)以重新添加它.
var marker = new google.maps.Marker({ position: myLatlng, title:"Hello World!" }); // To add the marker to the map, call setMap(); marker.setMap(map); // To remove the marker from the map marker.setMap(null);
https://developers.google.com/maps/documentation/javascript/markers
更新:因此,如果您想"重新加载"标记,您可以遍历当前活动标记的数组,将其地图设置为null,然后在地图上重置它们.