在谷歌地图中显示地图标记内容的事件

Event for showing map marker content in google map

本文关键字:事件 图标 谷歌地图 显示 地图      更新时间:2023-09-26

我的ionic应用程序中集成了谷歌地图。我希望每当地图出现时,我的标记就会出现在地图上,但这取决于"点击"事件。我已经变成了"空闲",但它甚至没有显示标记的内容。

问题:我应该把"点击"改成什么?

function getMap(lat, lon, content) {
        var latLng = new google.maps.LatLng(lat, lon);
        var mapOptions = {
          center: latLng,
          zoom: 15,
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        $scope.map = new google.maps.Map(document.getElementById("map"), mapOptions);
        //Wait until the map is loaded
        google.maps.event.addListenerOnce($scope.map, 'idle', function () {
          var marker = new google.maps.Marker({
            map: $scope.map,
            animation: google.maps.Animation.DROP,
            position: latLng
          });
          var infoWindow = new google.maps.InfoWindow({
            content: content
          });
          google.maps.event.addListener(marker, 'click', function () {
            infoWindow.open($scope.map, marker);
          });
        });
      }

只需删除google.maps.event.addListener(marker, 'click', function () {})并将infoWindow.open($scope.map, marker);单独保留