2017-08-04 59 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();