Google Maps InfoWindow without marker?

According to the document, the marker is optional with the info window, since this is achieved, please? I tried infowindow.open (map) and infowindow.open (map, null), but both do not produce anything.

+4
source share
2 answers

infowindow.open(map) does not make sense, since you need to specify the position at which infowindow should open, it also has a tapering rod that indicates the place where it should be pointed.

According to the documentation, Infowindows-InfoWindows can be attached to Marker objects (in this case their position is based on the location of the marker) or on the map itself with the specified LatLng.

So, if you don’t want the marker to open the info window, 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 InfowWindow- infowindow.setMap(null);

Hope to clear your doubts.

+4
source

If the position is set, there is no problem displaying 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); } 
+5
source

Source: https://habr.com/ru/post/1442444/


All Articles