0

検索後に情報ウィンドウを開いて、グーグルマップ上の位置にパンしようとしています。誰かが私を助けることができますか?ありがとうございました。

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

場所の検索が終了した後、情報ウィンドウを開くにはどうすればよいですか

4

1 に答える 1

1

マーカーに既存のクリックリスナーがあると仮定すると(マーカーを定義するコードを含めなかった場合)、最も簡単な方法は次のとおりです。

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")
}
于 2013-03-26T20:38:24.923 に答える