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

问题描述:

有人在点击Google地图标记时出现信息的按钮。谷歌地图标记上的联系人按钮

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

我是一个超级初学者,但我正在学习,至少可以帮助甚至让别人告诉我流程的确切名称即使您不知道如何去做,我也会尽力去做。

+0

你可以阅读关于这个“信息窗口” - https://developers.google.com/maps/documentation/javascript/infowindows – thanhnha1103

+0

你可以使用一种方式,这将作为“点击标记将取消隐藏按钮用户可以进行交互并点击该按钮将显示消息框弹出框并再次隐藏该按钮。并且可以将与所选标记相关的任何值传递给弹出窗口。“ –

当您声明您的infowindow时,您必须通过参数infowindowcontent。这是一个例子:

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,简单和infowindow有一个巨大的文本。

您可以通过在contentString中添加代码<button type="button">Click Me!</button>来添加按钮。

请查阅google's documentationinfowindows以及w3schools上的按钮示例。