开发者

Fetching markers from controller to refresh map with gmaps4rails

I have an app with multiple marker in a Rails3 application using gmaps4rails.

The map is loaded initially with all the markers but I have a filter fields on the page which I would like the user to filter different things which are stored in the db for the markers.

How to I trigger the map to call the controller with the parameters which would return a new json object, which I would then put in Gmaps4Rails.replaceMarkers function?

I'm u开发者_开发百科sing JQuery so it would probably be best to trigger this behavior from Jquery code.

Regards, Johann


Why don't you just set a event listener to those filter fields (or in a submit button), that then calls your_controller at the server via AJAX?

$("#yourSubmitButton").click(function() {
  $.getJSON('/get_markers.json', { filter: "value" }, function(json) {
    Gmaps.map.serviceObject.replaceMarkers(json);
  });
});

Didn't test the code.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜