admin管理员组

文章数量:1022989

I am wanting to trigger my placed_changed function when a submit button is clicked. So here is what I have, I have a searchbox I assign using google.maps.places.SearchBox and once I click enter with the search box on focus it triggers the event:

 google.maps.event.addListener(searchBox, 'places_changed', function() {
    runMainPopulation(searchBox.getPlaces());
  });

Which runs the next function. Now what I am trying to do is get this function to run once I click a search button or I click enter on my searchbox.

Suggestions, thoughts?

I am wanting to trigger my placed_changed function when a submit button is clicked. So here is what I have, I have a searchbox I assign using google.maps.places.SearchBox and once I click enter with the search box on focus it triggers the event:

 google.maps.event.addListener(searchBox, 'places_changed', function() {
    runMainPopulation(searchBox.getPlaces());
  });

Which runs the next function. Now what I am trying to do is get this function to run once I click a search button or I click enter on my searchbox.

Suggestions, thoughts?

Share Improve this question asked Jan 7, 2015 at 22:27 David BigaDavid Biga 2,8118 gold badges41 silver badges63 bronze badges 2
  • Does google.maps.event.trigger(searchBox,'places_changed') not work? – geocodezip Commented Jan 7, 2015 at 22:38
  • @geocodezip No it does not – David Biga Commented Jan 7, 2015 at 22:41
Add a ment  | 

1 Answer 1

Reset to default 5

I figured it out.

I had to initialize the Google searchBox via google method post.

For instance:

$(".submit-search").bind('click', function() {

    input.focus(); 
    var e = jQuery.Event("keydown");
    e.which = 13; // # Some key code value
    $(input).trigger(e);
    google.maps.event.trigger(searchBox, 'place_changed');
});

This would not work, I am not to sure as to why but it doesn't. submit-search is the button next to searchBox also defined as input.

Now if I initialize my input trigger focus and click through google.maps.event.trigger it works perfect:

$(".submit-search").bind('click', function() {
    google.maps.event.trigger(input, 'focus')
    google.maps.event.trigger(input, 'keydown', {
        keyCode: 13
    });
  });

I am wanting to trigger my placed_changed function when a submit button is clicked. So here is what I have, I have a searchbox I assign using google.maps.places.SearchBox and once I click enter with the search box on focus it triggers the event:

 google.maps.event.addListener(searchBox, 'places_changed', function() {
    runMainPopulation(searchBox.getPlaces());
  });

Which runs the next function. Now what I am trying to do is get this function to run once I click a search button or I click enter on my searchbox.

Suggestions, thoughts?

I am wanting to trigger my placed_changed function when a submit button is clicked. So here is what I have, I have a searchbox I assign using google.maps.places.SearchBox and once I click enter with the search box on focus it triggers the event:

 google.maps.event.addListener(searchBox, 'places_changed', function() {
    runMainPopulation(searchBox.getPlaces());
  });

Which runs the next function. Now what I am trying to do is get this function to run once I click a search button or I click enter on my searchbox.

Suggestions, thoughts?

Share Improve this question asked Jan 7, 2015 at 22:27 David BigaDavid Biga 2,8118 gold badges41 silver badges63 bronze badges 2
  • Does google.maps.event.trigger(searchBox,'places_changed') not work? – geocodezip Commented Jan 7, 2015 at 22:38
  • @geocodezip No it does not – David Biga Commented Jan 7, 2015 at 22:41
Add a ment  | 

1 Answer 1

Reset to default 5

I figured it out.

I had to initialize the Google searchBox via google method post.

For instance:

$(".submit-search").bind('click', function() {

    input.focus(); 
    var e = jQuery.Event("keydown");
    e.which = 13; // # Some key code value
    $(input).trigger(e);
    google.maps.event.trigger(searchBox, 'place_changed');
});

This would not work, I am not to sure as to why but it doesn't. submit-search is the button next to searchBox also defined as input.

Now if I initialize my input trigger focus and click through google.maps.event.trigger it works perfect:

$(".submit-search").bind('click', function() {
    google.maps.event.trigger(input, 'focus')
    google.maps.event.trigger(input, 'keydown', {
        keyCode: 13
    });
  });

本文标签: javascriptTrigger placeschanged in Google maps from submit buttonStack Overflow