mercredi 17 juin 2015

Refresh Google Map after ajax call for new data

In an html.erb with js, I am trying to plot a set of data (twitter tweets) on a google map using markers. I want to be able to update the map if it is double-clicked with new tweets. I decided to make an event listener for the double click action on the map like this:

`google.maps.event.addListener(map, 'dblclick', function(e) {
          alert(e.latLng.lat() +" "+ e.latLng.lng());
          //ajax callback
           function ajaxCallback(){
              return jQuery.ajax({
                  data: {lat: e.latLng.lat(), lng: + e.latLng.lng()},
                  dataType: 'script',
                  type: 'post',
                  url: "/map"
              });
          }
          var promise = ajaxCallback();
          promise.success(function () {
              initialize();
          });
      });`

which is in my initialize method. In the /map controller I am able to see the data sent correctly and the correct, new list of tweets sent in the response (using fiddler). However, the success function is never executed. I've tried a few different things to no avail. What am I missing about this process? I basically just need a way to postback/refresh with the new tweet data to be plotted.

Thanks!

Aucun commentaire:

Enregistrer un commentaire