0

I just want to display a default info window with the content The 123456789. So I am using the maps example from google, and changing the infowindow content. Simple as that.

<!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"><meta charset="utf-8">
    <title>Info windows</title>
    <style>html, body, #map-canvas {height: 100%;margin: 0px;padding: 0px}</style>
    <script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
    <script>
function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {zoom: 4,center: myLatlng};

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);                        
  var infowindow = new google.maps.InfoWindow({
      content: 'The 123456789'
  });

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Uluru (Ayers Rock)'
  });
  google.maps.event.addListener(marker, 'click', function() {
    infowindow.open(map,marker);
  });
}
google.maps.event.addDomListener(window, 'load', initialize);
    </script>
  </head><body><div id="map-canvas"></div></body></html>

I am getting this in both Firefox and Chrome (expected The 123456789). Only in IE I have the desired result. The rest of the text is wrapped and in chrome the scrollbar is also visible.

enter image description here

Now, as per the documentation, the InfoWindow should be expanded to fit my text, which it does if the content is a bit longer than the one I am testing. Is this a google maps styling issue and how can I simply display that text without custom InfoWindows and without hackish css?

edit

Tested the abode code again. The first time the infowindo is shown its problematic, the following times it's displayed as it should.

Odys
  • 8,951
  • 10
  • 69
  • 111

5 Answers5

0

Just tested your code and seems to be correct.

https://www.dropbox.com/s/i1bgvg74chb3hzt/Screenshot%202015-01-10%2017.53.36.png?dl=0

One thing you can do is, rather than create the infowindow full of content, you may wanna create the instance and, onclick set the content.

 google.maps.event.addListener(marker, 'click', function() {
   infowindow.setContent('something');
   infowindow.open(map,marker);
 });
geocodezip
  • 158,664
  • 13
  • 220
  • 245
bribeiro
  • 715
  • 5
  • 5
  • I've tried this in my real issue and didn't help. The first time the infoWindow has the correct size. If I close and reopen it, it is like this. I always set content before show. In which browser you got that result using the code from my question? – Odys Jan 11 '15 at 02:00
0

You could try adding a listener to the infowindow 'domready' event (using addListenerOnce), close infowindow, then reopen it.

proof of concept code snippet:

function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882, 131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  };

  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  var infowindow = new google.maps.InfoWindow({
    content: 'The 123456789'
  });

  var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Uluru (Ayers Rock)'
  });
  google.maps.event.addListener(marker, 'click', function() {
    google.maps.event.addListenerOnce(infowindow,'domready',function() {
      infowindow.close();
      infowindow.open(map,marker);
    });
    infowindow.open(map, marker);
  });
    google.maps.event.addListener(map, 'click', function() {
    infowindow.close();
  });
  google.maps.event.trigger(marker,'click');
}
google.maps.event.addDomListener(window, 'load', initialize);
html,
body,
#map-canvas {
  height: 100%;
  margin: 0px;
  padding: 0px
}
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<div id="map-canvas"></div>
geocodezip
  • 158,664
  • 13
  • 220
  • 245
  • I can replicate the issue using firefox. It seems resolved in Chrome. Just hit Ctrl+F5. The first time you click the marker it doesn't display correctly. Subsequent clicks work well. – Odys Jan 11 '15 at 03:20
  • The code snippet works for me in both Chrome (39.0.2171.95 m) and Firefox (34.0.5) [Ctrl+F5 & "Run code snippet"] – geocodezip Jan 11 '15 at 03:25
0

You should put the text in a '<div>' tag with style or class that has style attributes

   var infowindow = new google.maps.InfoWindow({
       content: '<div style="width: 10em;">The 123456789</div>'
   });
maurice
  • 171
  • 1
  • 6
0

Try to add

style="word-wrap:nospace"

as an attribute of your content

var infowindow = new google.maps.InfoWindow({
    content: '<p style="word-wrap:nospace">'+The 123456789+'</p>'
});
m.cainelli
  • 36
  • 3
0

This was due to global img styling. To revert it I just added

.gm-style img { max-width: none; }

Kudos to this answer.

Community
  • 1
  • 1
Odys
  • 8,951
  • 10
  • 69
  • 111