2017-08-04 60 views
0

我正在努力解決如何讓這些Google Map標記可過濾的問題。數據沒有通過數組輸入的奇怪做法的原因是因爲標記是從Wordpress帖子查詢創建的,而且這是成功運行的唯一方法。如何讓這些Google地圖標記可過濾?

基本上,我試圖讓這個過濾對選定的類別,以類似的方式向你怎麼會經常使用:for (i = 0; i < markers.length; i++) {

任何援助將非常感謝。

$('input.markers').each(function(){ 
     title  = $(this).data('title'); 
     description = $(this).data('description'); 
     lat   = $(this).data('lat'); 
     lng   = $(this).data('lng'); 
     url   = $(this).data('url'); 
     img   = $(this).data('featuredimage'); 
     comments = $(this).data('comments'); 

     //var to the box that will wrap the marker's content 
     var content = '<img src="' + img +'" class="img-responsive" />' + 
    '<div class="info_content">' + 
    '<h3>'+ title +'</h3>' + 
    '<p>'+ description +'</p>' + 
    '<p><small>'+ comments +'</small></p>' + 
    '<a class="btn btn-green" href="'+ url +'">READ MORE</a></div>'; 

     //create marker 
     var marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(lat, lng), 
      map:map, 
      title: title, 
      icon: image, 
     }); 

     var position = new google.maps.LatLng(lat, lng); 
     var info = $('#marker-info'); 

    $('#marker-close').click(function() { 
     $('#marker-info').fadeOut(); 
    }); 

}); 

回答

0

成功! - 管理把它變成一個數組。

var markers1 = $("input.markers").map(function() { 

title  = $(this).data('title'); 
lat   = $(this).data('lat'); 
lng   = $(this).data('lng'); 
category = $(this).data('category'); 
description = $(this).data('description'); 
url   = $(this).data('url'); 
img   = $(this).data('featuredimage'); 
comments = $(this).data('comments'); 

return [[ title, lat, lng, category, '<img src="' + img +'" class="img- 
responsive" />' +'<div class="info_content">' +'<h3>'+ title +'</h3>' +'<p>'+ 
description +'</p>' +'<p><small>'+ comments +'</small></p>' +'<a class="btn 
btn-green" href="'+ url +'">READ MORE</a></div>' ]]; 

}).toArray();