Reputation: 11
This is my input html
<input id="autocomplete" type="text" class="postulantes_search_location"
value="" onFocus="geolocate()">
it's work fine when i write an address and select an option of the dropdown. The problem is when i set a text, for example:
$('#autocomplete').val($(this).children('.saved-location').text());
and execute the trigger:
google.maps.event.trigger(autocomplete, 'place_changed');
and then, the function autocomplete.getPlace(
) return undefined
!
Upvotes: 1
Views: 1271
Reputation: 705
If it's still relevant, your problem is that google.maps.event.trigger
actually has three parameters, and you don't pass a place with your trigger:
google.maps.event.trigger(autocomplete, 'place_changed', {...} /*actual place data*/)
but you probably don't want that, because you don't have a place, just a string, so you shouldn't trigger the event, and should write your own processor, that, e.g., makes a request to google maps api
, like this:
$http.get('https://maps.googleapis.com/maps/api/geocode/json?address=' + $('#autocomplete').value() + '&key=' + GOOGLE_API_KEY
or any other method you'd like
Upvotes: 1