I am not able to place markers on the places which is already marked by google with other symbols .

后端 未结 2 400
梦毁少年i
梦毁少年i 2021-01-29 10:04

The info window and marker is not shown for the places which is already marked by google. for example: if you run the code and click anywhere , a marker and a info window will a

2条回答
  •  无人共我
    2021-01-29 10:49

    Hide those POIs:

    styles: [{
        featureType: "poi",
        elementType: "labels",
        stylers: [{
            visibility: "off"
        }]
    }]
    

    working code snippet:

    var map;
    var myCenter = new google.maps.LatLng(51.508742, -0.120850);
    
    function initialize() {
      var mapProp = {
        center: myCenter,
        zoom: 14,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [{
          featureType: "poi",
          elementType: "labels",
          stylers: [{
            visibility: "off"
          }]
        }]
      };
    
      map = new google.maps.Map(document.getElementById("googleMap"), mapProp);
    
      google.maps.event.addListener(map, 'click', function(event) {
        placeMarker(event.latLng);
      });
    }
    
    function placeMarker(location) {
      var marker = new google.maps.Marker({
        position: location,
        map: map,
      });
      var infowindow = new google.maps.InfoWindow({
        content: 'Latitude: ' + location.lat() + ' Longitude: ' + location.lng()
      });
      infowindow.open(map, marker);
    }
    
    google.maps.event.addDomListener(window, 'load', initialize);
    html,
    body,
    #googleMap {
      height: 100%;
      width: 100%;
      margin: 0px;
      padding: 0px
    }
    
    

提交回复
热议问题