question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Map works once / CSS height issues

See original GitHub issue

Hi im using iron router to load a template than contains a GoogleMap, it works perfectly the first time you navigate to the the route, but when access again, the map not work. Heres the code

Template.appraisalGeolocation.created = function() {
    GoogleMaps.load({v: '3', key: '12345', libraries: 'geometry'});
    GoogleMaps.ready('geolocation', geolocation.readyHandler);
}

Issue Analytics

  • State:open
  • Created 8 years ago
  • Reactions:1
  • Comments:27 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
ldongcommented, Oct 4, 2015

I had the similar issue, instead of putting googleMap in a template,

  <div class="map-container">
    {{> googleMap name="exampleMap" options=exampleMapOptions}}
  </div>

Just create a DOM

<div class="map" id="defaultMap"></div>

then call explicitly based on different event triggers.

Template.YourTemplateName.events({
  "click #map": function(e, t){
    if (!GoogleMaps.maps.defaultMap){
      console.log("Creating new defaultmap");
      GoogleMaps.create({
        name: 'defaultMap',
        element: document.getElementById('defaultMap'),
        options: {
          center: new google.maps.LatLng(37.72,-122.45),
          zoom: 8
        }
      });
    }
});
1reaction
mattiemooncommented, Jan 19, 2016

Hello.

The test app helped me find the problem after cutting out reems of code. Turns out a CSS class was causing the problem. From my example above, if I chuck away the following:

<div id="myContent" class="hide">

Everything works fine no matter how may times I leave and re-render the template containing the maps. The “hide” class was going to be used to handle some transition animations, and doesn’t actually map to anything concrete yet - my assumption is that code in my router file (that once the styles were defined) was running, and the timing of this versus the maps rendering was causing the problem (speculation again though - I’m new to most of this):

// This one was supposed to hide the current content
Router.onBeforeAction(function() {
  setTimeout(function () {
    $('#myContent').removeClass("fadeIn");
  });

  setTimeout(function () {
    $('#myContent').addClass("hide");   
  });
});

// This one was supposed to reveal the new content
Router.onAfterAction(function() {
  setTimeout(function () {
    $('#myContent').removeClass("hide");
  });

  setTimeout(function () {
    $('#myContent').addClass("animated fadeIn");
  });
});

I’m going to bin that and find another solution for the transitions - I’d much rather have the maps working!

Thanks again for the help @dburles; massively appreciated.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Issues with Google Map and 100% height? - Stack Overflow
Your map doesn't seem to load. Try specifying the canvas' width and height as absolute lengths rather than %. · Strangely enough, it...
Read more >
Google Maps weird height problem - HTML & CSS - SitePoint
Suddenly our maps stopped working. well they work, but with weird height. Nothing has changed on our side so it seems Google changed ......
Read more >
Google Maps not rendering with 100% height
The problem is, when I put on CSS height:100%, the map dont shows up. If I change it to 500px, it works fine....
Read more >
Get Started | Maps Static API - Google Developers
For more information, see Using Map IDs. markers (optional) define one or more ... inserted into an img or div tag with the...
Read more >
Configure width and height of 'pop-up' bubble on GMap - Drupal
Google maps are kind of weird for the way they work. The look of the map is somewhat inconsistant. The google map window...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found