Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps not showing, HTML

I'm currently working on an IP tracking program, but I have some problems with the google maps function, I can't get the map to show or put a marker on the IP location. Can anyone point me in the right directions?

Here is the code I've used for the map, I took it from googles own website.

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

<script>
  var map;
  function initMap() {
    map = new google.maps.Map(document.getElementById('map'), {
      center: {lat: -34.397, lng: 150.644},
      zoom: 8
    });
  }
</script>

 <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAnoX8LSgSg5-pRiF5_IzZ313VsNZzuo-4&callback=initMap"
 async defer></script>

Here's my complete code:

like image 774
Adam Avatar asked Apr 10 '26 15:04

Adam


2 Answers

To show map you need to provide height.

Add this height in your style for div with id map

 #map {
     height: 300px;
 }

Update:

if map container (with id map) should take up 100% of the height of the HTML body. Note that we must specifically declare those percentages for and as well.

 #map {
    height: 100%;
 }

 html, body {
    height: 100%;
    margin: 0;
    padding: 0;
 }
like image 69
Nenad Radak Avatar answered Apr 12 '26 05:04

Nenad Radak


In my case, div was like

<div id="map" style="height: 100%; width: 100%"></div>

but map appeared only when I've add position: absolute property explicitly. So, the result was

<div id="map" style="height: 100%; width: 100%; position: absolute"></div>

and it works.

like image 23
Anton Bochkarev Avatar answered Apr 12 '26 06:04

Anton Bochkarev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!