Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Maps infoWindow without marker?

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.

like image 466
Archdeacon Avatar asked Oct 27 '12 06:10

Archdeacon


People also ask

How do I put InfoWindow on marker?

Move an info windowAttach the info window to a new marker using the InfoWindow. open() method. Note: If you call open() without passing a marker, the InfoWindow will use the position specified upon construction through the InfoWindowOptions object literal.

How do I get rid of InfoWindow in Google Maps?

After constructing an InfoWindow, you must call open to display it on the map. The user can click the close button on the InfoWindow to remove it from the map, or the developer can call close() for the same effect.

How do I open multiple Infowindows in Google Maps?

By assigning the infowindow to a marker property, each marker can have it's own infowindow. This was how I approached the problem, with the relevant sample code. //create a marker object first, or instantiate it by passing a JSON to the constructor. //this can be done inside a for loop var infowindow = new google.


1 Answers

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);
}
like image 102
mesmoll Avatar answered Sep 28 '22 00:09

mesmoll