InfoWindow not Displaying

后端 未结 4 616
谎友^
谎友^ 2021-01-28 08:54

I\'m trying to have this so that someone clicks on the map, and an infoWindow pops up telling them that latlng. For now, just trying to figure out how to get an infoWindow to co

4条回答
  •  失恋的感觉
    2021-01-28 09:36

    The Map MouseEvent has a latLng property

    google.maps.event.addListener(map, 'click', function(event) 
    {
       new google.maps.InfoWindow({
                  map:map, 
                  content:"coordinates:"+event.latLng.toUrlValue(),
                  position:event.latLng});});
    }
    

    "map" is a reference to your google.maps.Map.

    Tested on this map by pasting this into the address bar, then clicking on the map:

    javascript:google.maps.event.addListener(map, 'click', function(event) {new google.maps.InfoWindow({map:map, content:"coordinates:"+event.latLng.toUrlValue(),position:event.latLng});});
    

提交回复
热议问题