-1

I would like to be able to place a marker on a Map and have it display the full address, including street number and name.

Currently, I have this somewhat working but for reasons I do not understand this only retrieves the Suburb name of where the marker is placed, even if I zoom right in and place the marker on a building.

I am following the Reverse Geocoding example here, combining it with the Add Marker script.

Would anyone know how to retrieve the full address when placing a marker?

My code is:

function addMarker(location) {

  geocoder.geocode({'location': location}, function(results, status) {
    if (status === google.maps.GeocoderStatus.OK) {
      if (results[1]) {
        map.setZoom(16);
        var marker = new google.maps.Marker({
          position: location,
          map: map
        });
        markers.push(marker);
        infowindow.setContent(results[1].formatted_address);
        var markerAddress = results[1].formatted_address;
        console.log(markerAddress);
        infowindow.open(map, marker);
      } else {
        window.alert('No results found');
      }
    } else {
      window.alert('Geocoder failed due to: ' + status);
    }
  });//GEOCODER

}//ADD MARKER
MeltingDog
  • 14,310
  • 43
  • 165
  • 295

1 Answers1

0

I had to change it to get the first level of results:

infowindow.setContent(results[1].formatted_address);

I don't know why they're broken up like that, but there you go

MeltingDog
  • 14,310
  • 43
  • 165
  • 295