Zaya
Zaya

Reputation: 41

Meteor google maps javascript api

how would one go about calling meteor method from inside GoogleMaps.ready callback? I am using dburles:google-maps package.

On the client

GoogleMaps.ready('eventsmap', function(map) {
   google.maps.event.addListener(map.instance, 'click', function(event) {
      Markers.insert({lat: event.latLng.lat(), lng: event.latLng.lng()});
   });
   ...

I tried following:

GoogleMaps.ready('eventsmap', function(map) {
   google.maps.event.addListener(map.instance, 'click', function(event) {
      var lat = event.latLng.lat();
      var lng = event.latLng.lng();
        Meteor.call("insertMarker", lat, lng, function(error, results) {
           if(error) {
              console.log(error.reason);
           } else {
              console.log(results);
           }
        });
   });
   ...

On the server I have "insertMarker" method which will insert marker into Markers collection. But got event is not defined exception. Any idea? Thank you.

Upvotes: 0

Views: 386

Answers (1)

Zaya
Zaya

Reputation: 41

Sorry guys, I just wrapped the method call inside if(event){...} conditional. It needed something to trigger the call. It works now, missed that one xD

Upvotes: 1

Related Questions