【问题标题】:Add infowindow for existing markers in google maps API为谷歌地图 API 中的现有标记添加信息窗口
【发布时间】:2015-04-20 00:09:54
【问题描述】:

我正在使用 javascript 中的 Google Maps API。我能够找到从一个点到另一个点的路线。但是,我需要编辑为位置上的标记显示的信息窗口。显示的默认信息会显示该地点的名称,有没有办法更改该信息以显示其他内容?

【问题讨论】:

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


【解决方案1】:

是的,您可以使用信息窗口做各种事情:

请参阅https://developers.google.com/maps/documentation/javascript/examples/infowindow-simple 以供参考。

信息窗口中一些自定义 html 的示例:

var infoWindowContent = '<div id="map-player-info-content">' +
    '<img class="player-pic" ng-src="' + (playerList[i].profilePic || 'img/smash-app-icon.png') + '">' +
    '<p><span class="text-bold">Player:</span> ' + playerList[i].tag + '</p>' +
    '<p><span class="text-bold">Game(s):</span> ' + playerList[i].games + '</p>' +
    '<p><span class="text-bold">Main(s):</span> ' + playerList[i].mains + '</p>' +
    '</div>';

var infowindow = new google.maps.InfoWindow({
    content: infoWindowContent
});

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Uluru (Ayers Rock)'
});

google.maps.event.addListener(marker, 'click', function () {
    infowindow.open(map, marker);
});

【讨论】:

    猜你喜欢
    • 2011-08-21
    • 1970-01-01
    • 1970-01-01
    • 2017-07-26
    • 2023-04-04
    • 1970-01-01
    • 1970-01-01
    • 2016-07-10
    相关资源
    最近更新 更多