[英]How can I add an Infowindow to a google map without a marker
如何在沒有標記的情況下將信息窗口添加到地圖,在這里我可以手動指定位置(緯度)。 有一個解決方案在這里 ,它使用的點擊位置,但我想指定它自己。 到目前為止,我嘗試了:
var infowindow = new google.maps.InfoWindow({
content: "You start here",
position: document.getElementById('start').value
});
在地圖初始化函數中並使用了以下代碼:
infowindow.open(map, new google.maps.LatLng(6.473500, 81.236577));
在偵聽器中,但是沒有用。 出現錯誤,表明它無法讀取打開信息窗口的提示。 有任何想法嗎?
您必須在公開調用中使用google.maps.Marker
對象設置位置,或者如果沒有標記,則直接設置位置。 這有效:
var infowindow = new google.maps.InfoWindow({
content: "You start here",
position: new google.maps.LatLng(6.473500, 81.236577)
});
infowindow.open(map);
代碼段:
function loadMap() { var map = new google.maps.Map(document.getElementById('map'), { zoom: 12, center: new google.maps.LatLng(6.473500, 81.236577) }); var infowindow = new google.maps.InfoWindow({ content: "You start here", position: new google.maps.LatLng(6.473500, 81.236577) }); infowindow.open(map); } window.onload = loadMap();
html, body, #map { height: 100%; width: 100%; }
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script> <div id="map"></div>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.