簡體   English   中英

搜索后如何打開信息窗口並平移到Google地圖上的位置

[英]how to open the info window after search and pan to the position on google map

搜索后,我嘗試打開信息窗口,然后平移到Google地圖上的位置。 有人能幫我嗎? 謝謝。

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")
    };
}

搜索完位置后我該怎么辦才能打開信息窗口

假設您在標記上有一個預先存在的點擊偵聽器(沒有包括定義標記的代碼),最簡單的方法是:

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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM