So, I have a search page with a location entry. If the user comes from another page with a search query, I want to programmatically enter this query into the input and run the changed location.
Here is what I still have:
var searchBox = new google.maps.places.SearchBox(input); $('input#location').val(searchQuery); google.maps.event.trigger(searchBox, 'places_changed');
However, this gives me the Cannot read property 'length' of undefined
error for this line of my places_changed
function:
var places = searchBox.getPlaces(); if (places.length == 0) { return; }
Thus, the searchBox
returns undefined
for getPlaces()
when the input is populated programmatically. How can I get around this?
UPDATE: Here is a JSFiddle example to show what I mean.
source share