title: Google maps API - add marker by address javascript
body: <p>I have database of places with addresses and I want to add markers on google maps.</p>
  
  <p>It shows only the default marker, seems like the geocoder.geocode() does nothing. For an example I'm trying to add a marker on " New York City", with no success.</p>
  
  <pre><code>&lt;script&gt;
      var geocoder;
      var map;
      var address = "new york city";
      geocoder = new google.maps.Geocoder();
      function initMap() {
          var uluru = { lat: -25.363, lng: 131.044 };
          var map = new google.maps.Map(document.getElementById('map'), {
              zoom: 4,
              center: uluru
          });
          var marker = new google.maps.Marker({
              position: uluru,
              map: map
          });
          codeAddress(address);
  
      }
  
      function codeAddress(address) {
  
          geocoder.geocode({ 'address': address }, function (results, status) {
              if (status == 'OK') {
                      var marker = new google.maps.Marker({
                      position: address,
                      map: map
                  });
              } else {
                  alert('Geocode was not successful for the following reason: ' + status);
              }
          });
      }
  
  
  &lt;/script&gt;
  &lt;script src="https://maps.googleapis.com/maps/api/js?key=XXX&amp;callback=initMap"
      async defer&gt;&lt;/script&gt;
  </code></pre>