title: Why can't I get the coordinates from the marker of google maps places api?
body: <p>I want to get the latitude and longitude from the marker in google maps when it is moved to another position.</p>
  
  <p>I have searched and found the answer but I really don't know what am I doing wrong. I can get the coordinates when you select a search result address but when the marker drags and drops to a new position the coordinates don't change...</p>
  
  <pre><code>    &lt;script&gt;
  
    function initMap() {
      var map = new google.maps.Map(document.getElementById('map'), {
        center: {lat: 38.241997, lng: 21.736244},
        zoom: 13
      });
      var card = document.getElementById('pac-card');
      var input = document.getElementById('pac-input');
      var types = document.getElementById('type-selector');
      var strictBounds = document.getElementById('strict-bounds-selector');
  
      map.controls[google.maps.ControlPosition.TOP_RIGHT].push(card);
  
      var autocomplete = new google.maps.places.Autocomplete(input);
  
      // Bind the map's bounds (viewport) property to the autocomplete object,
      // so that the autocomplete requests use the current map bounds for the
      // bounds option in the request.
      autocomplete.bindTo('bounds', map);
  
      // Set the data fields to return when the user selects a place.
      autocomplete.setFields(
          ['address_components', 'geometry', 'icon', 'name']);
  
      var infowindow = new google.maps.InfoWindow();
      var infowindowContent = document.getElementById('infowindow-content');
      infowindow.setContent(infowindowContent);
      var marker = new google.maps.Marker({
        map: map,
    draggable: true,
        anchorPoint: new google.maps.Point(0, -29)
      });
  
  google.maps.event.addListener(marker, 'dragend', function() {
  document.getElementById('Lat').value = marker.getPosition().lat();
      document.getElementById('Lng').value = marker.getPosition().lng();
  });
  
      autocomplete.addListener('place_changed', function() {
        infowindow.close();
        marker.setVisible(true);
        var place = autocomplete.getPlace();
    document.getElementById('Lat').value = place.geometry.location.lat();
        document.getElementById('Lng').value = place.geometry.location.lng();
  
        if (!place.geometry) {
          window.alert("No details available for input: '" + place.name + "'");
          return;
        }
  
        // If the place has a geometry, then present it on a map.
        if (place.geometry.viewport) {
          map.fitBounds(place.geometry.viewport);
        } else {
          map.setCenter(place.geometry.location);
          map.setZoom(17);  // Why 17? Because it looks good.
        }
        marker.setPosition(place.geometry.location);
        marker.setVisible(true);
  
  
        var address = '';
        if (place.address_components) {
          address = [
            (place.address_components[0] &amp;&amp; place.address_components[0].short_name || ''),
            (place.address_components[1] &amp;&amp; place.address_components[1].short_name || ''),
            (place.address_components[2] &amp;&amp; place.address_components[2].short_name || '')
          ].join(' ');
        }
  
        infowindowContent.children['place-icon'].src = place.icon;
        infowindowContent.children['place-name'].textContent = place.name;
        infowindowContent.children['place-address'].textContent = address;
        infowindow.open(map, marker);
      });
  
  
      document.getElementById('use-strict-bounds')
          .addEventListener('click', function() {
            console.log('Checkbox clicked! New state=' + this.checked);
            autocomplete.setOptions({strictBounds: this.checked});
          });
    }
  
  
  
  &lt;/script&gt;
  </code></pre>
  
  <p>I then assign the coordinates in two form inputs (Lat and Lng) but I don't post that code because I am sure there is no problem. As I told you with place_changed it works perfect. Only with the marker drag and drop nothing happens. Thank you.</p>