2014-02-06 20 views
0

我想使标记与markerClusterer成簇,但我无法使用jQuery UI地图获取地图实例。 JS在jQuery UI地图中获取地图的实例

尝试:

变种地图= $( '#map_canvas提供')GMAP( '的GetMap');。 或 var map = $('map_canvas')。gmap('get','map');

之后: var markerCluster = new MarkerClusterer(map,allMarkers);

但有错误

谢谢

+0

第二次尝试是正确的,无法回答没有更多细节 –

+1

什么错误?你的其他代码是什么样的? – geocodezip

回答

0

尝试这个。没有错误但没有群集...

$('#map_canvas').gmap({ 'callback': function() { 
    var self = this;  
    $.getJSON('Data/markers.json', function (data) { 
     $.each(data.markers, function (i, marker) { 
     self.addMarker({ 'position': new google.maps.LatLng(marker.latitude,marker.longitude)}).click(function() { 
      $.ajax({ 
       type: "GET", 
       url: "/LocoMap/LocoMap/InfoMobilePartialView/", 
       data: { latitude: marker.latitude, longitude: marker.longitude}, 
       success: function (data) { 
       $("#marker-info").remove();  
       $(document.body).append("<div id='marker-info' data-role ='page'> </div>"); 
       var $contentDiv = $("#marker-info"); 
       $contentDiv.html(data).trigger('create'); 
       $.mobile.changePage("#marker-info", { changeHash: false, type: "get", transition: 'pop',rel:"external" }); 
      }, 
       error: function (errorData) { onError(errorData); } 
       }); 
      }); 
     }); 
    }); 

      self.set('MarkerClusterer', new MarkerClusterer(this.get('map'), this.get('markers'))); 

}});

0
$('#map_canvas').gmap({'zoom': 2, 'disableDefaultUI':true}).bind('init', function(evt, map) { 
     $.getJSON('Data/markers.json', function(data) { 
     $.each(data.markers, function(i, m)         
      $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(m.latitude, m.longitude), 'bounds':true }); 
      }); 
     });          


$('#map_canvas').gmap('set', 'MarkerClusterer', new MarkerClusterer(map,$(this).gmap('get', 'markers'))); 
}); 

with no errors and no clusters 
it seems **$(this).gmap('get', 'markers')));** returns Array[0]