Google Maps Button to Jump to new Location


#1

Hi All

So I am new to Meteor development and loving it. I am currently working with the dburles Google Maps package. It was a breeze to setup and get going.

I am having an issue with something now and I seem to have hit a brick wall. I want the map to load with Location 1 (In this case, Johannesburg, South Africa), and then when a button on the page is clicked, the Map should jump and recenter on Location 2 (Cape Town, South Africa).

I have tried adding click events, and am not getting any errors. But for the love of me I can’t get the map to move to a second location!

Any help would be awesome


#3

Hey @sydcpt you’ll want to use an autorun to trigger changes to the map.

It might look something like:

Template.myMap.onCreated(function() {
  GoogleMaps.ready(map => {
    this.autorun(function() {
      const location = Session.get('location');
      if (location) {
        // do something!
        // map.instance.xxx
      }
    });
  });
});

Then on your click event just update the session Session.set('location', '...');


#4

Fantastic. Thanks for the help and the brilliant package.