谷歌地图标记上的联系人按钮

时间:2017-10-07 04:09:15

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

当有人点击Google地图标记时,是否有办法在信息上显示按钮。

我试图让人们点击其中一个标记位置时会弹出与该标记连接的信息,然后弹出一个消息按钮,导致单击时弹出一个消息框。

我是一个超级初学者,但我正在学习,至少可以帮助甚至让别人告诉我即使你不知道怎么做也要尝试做的过程的确切名称。

1 个答案:

答案 0 :(得分:0)

当您声明infowindow时,您必须传递content参数中的infowindow。这是一个例子:

function initMap() {
    var uluru = {lat: -25.363, lng: 131.044};
    var map = new google.maps.Map(document.getElementById('map'), {
      zoom: 4,
      center: uluru
    });

    var contentString = '<div id="content">'+
        '<div id="siteNotice">'+
        '</div>'+
        '<h1 id="firstHeading" class="firstHeading">Uluru</h1>'+
        '<div id="bodyContent">'+
        '<p><b>Uluru</b>, also referred to as <b>Ayers Rock</b>, is a large ' +
        'sandstone rock formation in the southern part of the '+
        'Northern Territory, central Australia. It lies 335&#160;km (208&#160;mi) '+
        'south west of the nearest large town, Alice Springs; 450&#160;km '+
        '(280&#160;mi) by road. Kata Tjuta and Uluru are the two major '+
        'features of the Uluru - Kata Tjuta National Park. Uluru is '+
        'sacred to the Pitjantjatjara and Yankunytjatjara, the '+
        'Aboriginal people of the area. It has many springs, waterholes, '+
        'rock caves and ancient paintings. Uluru is listed as a World '+
        'Heritage Site.</p>'+
        '<p>Attribution: Uluru, <a href="https://en.wikipedia.org/w/index.php?title=Uluru&oldid=297882194">'+
        'https://en.wikipedia.org/w/index.php?title=Uluru</a> '+
        '(last visited June 22, 2009).</p>'+
        '</div>'+
        '</div>';

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

    var marker = new google.maps.Marker({
      position: uluru,
      map: map,
      title: 'Uluru (Ayers Rock)'
    });
    marker.addListener('click', function() {
      infowindow.open(map, marker);
    });
  }

在这里,您可以定义一个简单的map,一个简单的marker和一个带有大文本的infowindow

您可以在<button type="button">Click Me!</button>

中添加此代码contentString来添加按钮

请参阅关于infowindows的{​​{3}}以及google's documentation上的按钮示例。