A
A
alysenko2016-12-15 13:35:15
JavaScript
alysenko, 2016-12-15 13:35:15

How to find a marker on Google maps by coordinates or id?

There is the following situation.
Markers of certain points are plotted on Google maps.
There is also a list of these points.

<ul>
     <li data-id='1' data-lat='...' data-lng='...'>point 1</li>
     <li data-id='2' data-lat='...' data-lng='...'>point 2</li>
     <li data-id='3' data-lat='...' data-lng='...'>point 3</li>
  </ul>

It is necessary to implement a connection between the list of points and the markers on the map that correspond to them.
That is, when I click on a list item on the map, the marker that corresponds to this point should be highlighted.
How to find a marker by its position or id?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alysenko, 2016-12-15
@alysenko

Found a solution (I don't know how correct). All markers are an array. When clicking on an element of the list, I take the id value that corresponds to the array index, and the marker corresponds to it accordingly

$(document).on('click', '.selector', function(event) {
  var id= $(this).data('id');
  toggleBounce(markers[id]);
});

function toggleBounce(marker) {
  if (marker.getAnimation() !== null) {
    marker.setAnimation(null);
  } else {
    marker.setAnimation(google.maps.Animation.BOUNCE);
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question