如何自定义地图并删除“ POI图层”?

时间:2019-04-08 12:36:17

标签: javascript google-maps google-maps-api-3

在嵌入式Google地图上(例如此处-https://www.familienfreunde.de/4.php?Nummer=132700000302),您会看到很多景点。

我要删除它们。

<script>
function initMap() {
  var latlng = new google.maps.LatLng(51.3267379,12.3653812);
  var myOptions = {
 zoom: 19,
 center: latlng,
 mapTypeControlOptions: {
 mapTypeIds: ["roadmap", "satellite"]
}
 };
  map = new google.maps.Map(document.getElementById("map"), myOptions);
  var box_html = "<h5>Gymnasium Gerda Taro Schule</h5><p>04107 Leipzig<br /><b><a href=\"4.php?Nummer=132700000302\">Profil anzeigen</a></b></p>";
  var icon = new google.maps.MarkerImage('/bilder/marker4.png'); 
  var marker = add_marker(51.3267379,12.3653812,'Gymnasium Gerda Taro Schule',box_html,icon);
  marker.setMap(map);
        var box_html = "<h5>Rechtsanwalt Henry Bach</h5><p>04107 Leipzig<br /><b><a href=\"22.php?Nummer=378\">Profil anzeigen</a></b></p>";
  var icon = new google.maps.MarkerImage('/bilder/marker22.png'); 
  var marker = add_marker(51.3339224,12.3741322,'Rechtsanwalt Henry Bach',box_html,icon);
  marker.setMap(map); }
function add_marker(lat,lng,title,box_html,icon) {
     var infowindow = new google.maps.InfoWindow({
     content: box_html
   });
     var marker = new google.maps.Marker({
      position: new google.maps.LatLng(lat,lng),
      map: map,
      icon: icon,
      title: title
    });
     google.maps.event.addListener(marker, 'click', function() {
   infowindow.open(map,marker);
  });
     google.maps.event.addListener(map, 'dragstart', function() {
    infowindow.close();
   });
     return marker;
    }
</script> 
<script src="https://maps.googleapis.com/maps/api/js?key=UNSERKEY&callback=initMap" async defer></script>

(为清楚起见,我仅删除了一些标记。)

1 个答案:

答案 0 :(得分:0)

您可以尝试使用styles属性查看POI的可见性

    function initMap() {
      var latlng = new google.maps.LatLng(51.3267379,12.3653812);
      var myOptions = {
     zoom: 19,
     center: latlng,
     styles = [
        {
            featureType: "poi",
            elementType: "labels",
            stylers: [
                  { visibility: "off" }
            ]
        }
    ];
     mapTypeControlOptions: {
     mapTypeIds: ["roadmap", "satellite"]
    }