2017-10-07 57 views
-1

有人在點擊Google地圖標記時出現信息的按鈕。谷歌地圖標記上的聯繫人按鈕

我試圖讓人們點擊一個標記位置時,與該標記連接的信息彈出,然後是一個消息按鈕,當點擊時會彈出一個消息框。

我是一個超級初學者,但我正在學習,至少可以幫助甚至讓別人告訴我流程的確切名稱即使您不知道如何去做,我也會盡力去做。

+0

你可以閱讀關於這個「信息窗口」 - https://developers.google.com/maps/documentation/javascript/infowindows – thanhnha1103

+0

你可以使用一種方式,這將作爲「點擊標記將取消隱藏按鈕用戶可以進行交互並點擊該按鈕將顯示消息框彈出框並再次隱藏該按鈕。並且可以將與所選標記相關的任何值傳遞給彈出窗口。「 –

回答

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上的按鈕示例。