5
votes

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,null) but both produce nothing.

3
What do you want and and what have you tried, post here the code.The Alpha

3 Answers

5
votes

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.

9
votes

If the position is set, there is no problem showing the info window

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
  zoom: 6,
  center: {lat: 55.6761, lng: 12.5683},
  mapTypeId: google.maps.MapTypeId.TERRAIN
});
var infowindow = new google.maps.InfoWindow({
  content: "Copenhagen"
});
infowindow.setPosition({lat: 55.6761, lng: 12.5683});
infowindow.open(map);
}
2
votes

Since the api has changed, it is not possible to set position on info window any more. the solution i found is to add a marker to the map with visibility false:

this.map.addMarker({
        position: {
          'lat': sites[0].latitude,
          'lng': sites[0].longitude
        },
        // setting visible false since the icon will be the poi icon
        visible: false
      }).then((marker: Marker) => {

        this.htmInfoWindow.open(marker);
      });