Google Maps does not appear on the webpage, but does appear on localhost

So I am trying to embed google maps on a website and it works fine on my localhost and I can see it fine. However, when I upload this to my hosting company, the map doesn't show up at all. When I check the item and check the console, I don't see any errors. Code below:

<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=MYAPIKEY"></script>
<script>
  function initialize() {
    var mapCanvas = document.getElementById('map-canvas');
    var myLatlng = new google.maps.LatLng(53.092975, -7.895479);

    var mapOptions = {
      center: myLatlng,
      zoom:16,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }

    var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

    var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'LCCEurotex'
    });

  }
  google.maps.event.addDomListener(window, 'load', initialize);
</script>

      

I have no idea what might be causing this as my code looks the same as it does in google documentation. Any ideas on what might be causing this would be great. Thanks for any help!

+3


source to share


2 answers


Move this piece of code to the footer page. Maybe you have a map snapping and the container container is not loaded, furthermore the tray adds a cap to the default map_canvas id in your css.

    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyDo7nFkoUthlGms4De0miS4EPfupB5x0cY"></script>

    <script>
      function initialize() {
        var mapCanvas = document.getElementById('map-canvas');
        var myLatlng = new google.maps.LatLng(53.092975, -7.895479);

        var mapOptions = {
          center: myLatlng,
          zoom:16,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

        var marker = new google.maps.Marker({
          position: myLatlng,
          map: map,
          title: 'LCCEurotex'
        });


      }
      google.maps.event.addDomListener(window, 'load', initialize);
    </script>

      



In your CSS

div#map-canvas {
  height: 500px !important;
}

      

+1


source


Only add http: // to google maps api url, change this line:

<script type="text/javascript" src="maps.google.com/maps/api/js?sensor=false"></script>

      



Thus:

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script> 

      

+1


source







All Articles