简体   繁体   English

如何在Google Maker地图名称和说明中添加

[英]How to add in Google maker map name and description

I have a problem. 我有个问题。 This is google map JavaScript code. 这是Google Map JavaScript代码。 I want to add marker Name and description and its will showed in mouse hover effect. 我想添加标记名称和描述,它将在鼠标悬停效果中显示。 Thanksa 谢谢

 <script>
      var map;
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          zoom: 15,
          center: new google.maps.LatLng(-33.91722, 151.23064),
          mapTypeId: 'roadmap'
        });
        var icons = {
          parking: {
            icon: 'icon32.png'
          }
        };
        var features = [
          {
            position: new google.maps.LatLng(-33.91721, 151.22630),
            type: 'parking'
          }, {
            position: new google.maps.LatLng(-33.91539, 151.22820),
            type: 'parking'
          }
        ];
        // Create markers.
        features.forEach(function(feature) {
          var marker = new google.maps.Marker({
            position: feature.position,
            icon: icons[feature.type].icon,
            map: map
          });
        });
      }
    </script>

You should use this modified code to achieve the goal: 您应该使用此修改后的代码来实现目标:

<script>
    var infowindows = [];
    var map;
    var Markers = [
        ['Palace of Westminster', 'London', '51.499332, -0.124659'],
        ['Tower Bridge', 'London', '51.505396, -0.075432'], 
    ];
    function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
            zoom: 15,
            center: new google.maps.LatLng(51.485570, -0.129103),
            mapTypeId: 'roadmap'
        });
        var icons = {
            parking: {
                icon: 'icon32.png'
            }
        };

        // Create markers.
        for (var i=0; i<Markers.length; i++) {
            var contentString = '<div class="infoWindow"><strong>' + Markers[i][0] + '<\/strong>' +
                '<br>' + Markers[i][1] + '<\/div>';
            var infowindow = new google.maps.InfoWindow({
                content: contentString
            });

            latLngString = Markers[i][2];
            latLngString = latLngString.replace("(","");
            latLngString = latLngString.replace(")","");
            latLngString = latLngString.trim();         

            var lat = latLngString.split(",")[0].trim();
            var lng = latLngString.split(",")[1].trim();
            var latLng = new google.maps.LatLng(lat, lng);

            var marker = new google.maps.Marker({
                map: map,
                position: latLng,
                icon: icons[parking].icon,              
            });
            google.maps.event.addListener(marker, 'mouseover', function() {
                infowindow.open(map, marker);
            });
            google.maps.event.addListener(marker, 'mouseout', function() {
                infowindow.close(map, marker);
            });
            infowindows.push(infowindow);
        }
    }
</script>

Array Markers contains information on name, location and coordinates of each marker to put on map. 阵列标记包含有关要放置在地图上的每个标记的名称,位置和坐标的信息。 Edit it to put your own markers on the map. 编辑它以在地图上放置您自己的标记。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM