I try to open the info window after search and pan to the position on google map. 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")
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.