-
Notifications
You must be signed in to change notification settings - Fork 382
Dynamic (or Ajax) map refresh
Gmaps4rails allows you to update your map on the fly.
Check here the valid json format you should provide: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Control-what-I-display
If you want to create a callback called once the map and items are created, include the following code in your view:
<script type="text/javascript" charset="utf-8">
Gmaps.map.callback = function() {
//whatever you want here
}
</script>
If you want to replace the current markers with your new ones:
Gmaps.map.replaceMarkers(your_markers_json_array); //this is a JS function
If you want to add markers to those already displayed (it doesn't check duplicates):
Gmaps.map.addMarkers(your_markers_json_array); //this is a JS function
You can generate javascript to update your map the same way it's used to create it. Simply use the to_gmaps4rails
method after your hash of variables to display as described here: https://github.com/apneadiving/Google-Maps-for-Rails/wiki/Methods
Notice that you can use all javascript functions written in the js files directly. I hope the files have enough comments to make everything clear.