Jahn Schlosser
Jahn Schlosser

Reputation: 79

Implementing a search function for a marker

I have Markers setup with gmaps4rails.

Now I want to implement a classic search function.

If I find one object, it should directly show the marker.infowindow

How do I open it directly?

I tried:

function focusSearch() {
            handler.map.centerOn({ lat: <%[email protected] %>, lng: <%[email protected] %>});
            handler.getMap().setZoom(16);
            marker = <%[email protected]%>
            marker.infowindow.open(map, marker.serviceObject);
      }

But I guess I am going wrong there... Anyone can help?

If you have an Idea how to directly use the #search:params, I am happy!

Thanks for helping out!

Upvotes: 0

Views: 49

Answers (1)

apneadiving
apneadiving

Reputation: 115511

I've created a plunkr with working code here.

Basically steps are:

  • associate the marker to the original json data where ids are available

  • search the marker list for the id you expect

  • trigger the 'click' google map event on the marker which triggers pan + infowindow

Upvotes: 1

Related Questions