admin管理员组文章数量:1415139
I have a table with search results and an array of markers for the results. Every element has an ID, and if a user clicks on a marker, the page scrolls to the search result (I'm just changing window.location.hash).
Is it possible to do it vice-versa? Users click on the search result and the infoWindow for a marker appears.
I have a table with search results and an array of markers for the results. Every element has an ID, and if a user clicks on a marker, the page scrolls to the search result (I'm just changing window.location.hash).
Is it possible to do it vice-versa? Users click on the search result and the infoWindow for a marker appears.
Share Improve this question edited Jul 3, 2011 at 12:35 Trott 70.3k27 gold badges182 silver badges217 bronze badges asked Jul 3, 2011 at 9:17 Daniel J FDaniel J F 1,0642 gold badges16 silver badges31 bronze badges 1- "if a user clicks on a marker, the page scrolls to the search result " can you help me for this ? – Kanagasabapathy Rajkumar Commented Mar 14, 2014 at 10:37
1 Answer
Reset to default 3I assume you mean that in the map the marker associated to the search result scrolls into view?
As long as your search result has a click event that contains some unique identifier for the marker you want to appear, sure it will work. A site I'm currently managing has a sidebar of search results where when you click the result it will scroll the marker into view on the map and show the infowindow. The code invoked by the click handler looks something like so (sans some error handling and other uninteresting parts for your question):
function MarkerZoomTo(markerIdentifier) {
pt = gMarkers[markerIdentifier].getPosition();
newpt = new google.maps.LatLng(pt.lat() + .02, pt.lng());
map.panTo(newpt);
if (infoWindow) {
infoWindow.close();
}
infoWindow.setContent(gMarkers[markerIdentifier].get('iwcontent'));
infoWindow.setPosition(gMarkers[markerIdentifier].getPosition());
infoWindow.open(map, gMarkers[markerIdentifier]);
}
I pass the unique marker identifier to the function, get the specific marker out of my marker array, get it's lat/lng position, create a LatLng object, and pan to that location.
The rest is just dressing to retrieve the content for the infowindow and set it's position which you could do any way you see fit.
And finally, just open the infowindow for the marker.
Good luck!
本文标签: javascriptHow to find a certain marker on Google MapStack Overflow
版权声明:本文标题:javascript - How to find a certain marker on Google Map? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745195712a2647124.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论