google maps jquery + geocoder

by rixlabs

HTML

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

    
      <script>

    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9utzeckd8pV-IwFik5jVgTtG84QhDjfI&callback="
    async defer></script>
  </body>

CSS

html, body {
        height: 100%;
        margin: 0;
        padding: 0;
      }
      #map {
        height: 100%;
      }

JavaScript

var map;

$(document).ready(function(){
    initMap();
function drawMarker(map, location) {
		console.log(location);
    return new google.maps.Marker({
        map: map,
        position: location
    });
}
var geocoder = new google.maps.Geocoder;
function codeAddress(address) {
    geocoder.geocode({ 'address': address}, function(results, status) {

        if (status == google.maps.GeocoderStatus.OK) {
            drawMarker(map,results[0].geometry.location);
        }
    });
}

codeAddress("Sydney, NSW");

});

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

 
}