I am trying to use autocomplete from the Google Places API. I have autocomplete configured and working, but I want to add a listener so that I can use the information from PlacesResult elsewhere.
To test the functionality, I am trying to prove that the listener works by creating a warning window and writing place.name to a. Nothing works, so the listener is clearly configured incorrectly, I suppose, but I cannot understand how I wrote it incorrectly.
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?libraries=places&sensor=false">
</script>
<script type="text/javascript">
function initialize(){
var input = document.getElementById('name');
var autocomplete = new google.maps.places.Autocomplete(input);
}
google.maps.event.addDomListener(window, 'load', initialize);
google.maps.event.addListener(autocomplete, 'place_changed', function(){
var place = autocomplete.getPlace();
alert("This function is working!");
document.getElementById("receiver").innerHTML=place.name;
});
</script>
source
share