Google Maps infoWindow without marker?

后端 未结 3 1399
名媛妹妹
名媛妹妹 2021-01-05 23:46

According to the documention a marker is optional with an infoWindow, so how is this achieved please? I have tried infowindow.open(map) and infowindow.open(map,

3条回答
  •  [愿得一人]
    2021-01-06 00:02

    infowindow.open(map) makes no sense since you need to specify the position where the infowindow should open, also it has a tapered stem which specifies the location where it should point.

    According to the documentation of Infowindows- InfoWindows may be attached to either Marker objects (in which case their position is based on the marker's location) or on the map itself at a specified LatLng.

    So if you donot want the marker to open the infowindow, use the map click event-

    var iwindow= new google.maps.InfoWindow;
        google.maps.event.addListener(map,'click',function(event)
        {
             iwindow.setContent(event.latLng.lat()+","+event.latLng.lng());
             iwindow.open(map,this); 
             iwindow.open(map,this);
        });
    

    And to close a InfowWindow- infowindow.setMap(null);

    Hope that cleared your doubts.

提交回复
热议问题