我想在初始化地图标记的时候放置标记 但是infowindow的内容没有显示,我在JSFiddle.net上使用了相同的代码。 谷歌地图密钥是否有任何问题
function initialize()
{
var map;
var myCenter = new google.maps.LatLng(18.527362399999998,73.8783206);
var mapProp = {
center:myCenter,
zoom:10,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),mapProp);
addMarker(myCenter, 'Center of Map', map,"gg");
}
function addMarker(latlng,title,map,info){
var marker = new google.maps.Marker({
position: latlng,
map: map,
zoom:12,
title: title,
draggable:true
});
var infowindow = new google.maps.InfoWindow();
//creating new infowindow
infowindow.close();//hide the infowindow
infowindow.setContent('Latitude: ');
infowindow.open(map,marker);
}
<html>
<body onload="initialize()" style="background-color: #EFEFEF">
<div id="mapDiv" style="display: none;">
<p>
<input type="text" size="60" id="mapAdd" name="address" />
<input type="button" name="getLocation" value="Get Location" onclick="closeMap();"/>
</p>
<input type="text" id="lat"/>
<input type="text" id="lng"/>
<div id="map-canvas"></div>
</div>
</body>
</html>
答案 0 :(得分:1)
创建info
InfoWindow
变量
var infowindow = new google.maps.InfoWindow(
'content' : info
);
但是我可以看到你使用了setContent
,请检查z-index。
答案 1 :(得分:0)
问题:
工作代码段:
function initialize()
{
var map;
var myCenter = new google.maps.LatLng(18.527362399999998,73.8783206);
var mapProp = {
center:myCenter,
zoom:10,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map-canvas"),mapProp);
addMarker(myCenter, 'Center of Map', map,"gg");
}
function addMarker(latlng,title,map,info){
var marker = new google.maps.Marker({
position: latlng,
map: map,
zoom:12,
title: title,
draggable:true
});
var infowindow = new google.maps.InfoWindow();
//creating new infowindow
infowindow.close();//hide the infowindow
infowindow.setContent('Latitude: ');
infowindow.open(map,marker);
}
<html>
<script src="https://maps.googleapis.com/maps/api/js"></script>
<body onload="initialize()" style="background-color: #EFEFEF">
<div id="mapDiv">
<p>
<input type="text" size="60" id="mapAdd" name="address" />
<input type="button" name="getLocation" value="Get Location" onclick="closeMap();"/>
</p>
<input type="text" id="lat"/>
<input type="text" id="lng"/>
<div id="map-canvas" style="height:500px; width:500px;"></div>
</div>
</body>
</html>