[英]how to open the info window after search and pan to the position on google map
I try to open the info window after search and pan to the position on google map. 搜索后,我尝试打开信息窗口,然后平移到Google地图上的位置。 Can someone help me?
有人能帮我吗? Thank you.
谢谢。
var availableTags = [];
for (i=0;i<mapLocationsJSON.length;i++){
availableTags[i]=mapLocationsJSON[i].title;
}
//This is the autocomplete text field
$(function() {
$( "#search" ).autocomplete({
source: availableTags
});
});
//Insert the function here for what you want it to do when you search
function myFunc(searchTerm){
var validSearch=false;
var markerNumber;
//Check to see if the term they searched for matches any of the locations in the map data
for (i=0;i<mapLocationsJSON.length;i++){
if(searchTerm==mapLocationsJSON[i].title){
validSearch=true;
markerNumber=i;
break;
}
}
if(validSearch){
//Pan to the position and zoom in.
map.panTo(markers[markerNumber].getPosition());
map.setZoom(7);
//I'm not sure how to open the info window.... ?
//infowindow.open(map,markers[markerNumber]);
}else{
//if the data doesn't match a term, ask them to search again.
alert("Please try again")
};
}
What should I do to open info window after finish searching the location 搜索完位置后我该怎么办才能打开信息窗口
Assuming you have a pre-existing click listener on the marker (you didn't include your code that defines the marker), the simplest way is: 假设您在标记上有一个预先存在的点击侦听器(没有包括定义标记的代码),最简单的方法是:
if(validSearch){
//Pan to the position and zoom in.
map.panTo(markers[markerNumber].getPosition());
map.setZoom(7);
// click on the marker
google.maps.event.trigger(markers[markerNumber],'click');
}else{
//if the data doesn't match a term, ask them to search again.
alert("Please try again")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.