【问题标题】:Infowindow google maps api numbersInfowindow 谷歌地图 API 编号
【发布时间】:2015-12-03 12:30:29
【问题描述】:
我正在尝试通过单击标记在 google maps api infowindow 中显示日期格式。
我做不到。这是一个在点击标记时只显示字符串的错误吗?
content = "19/11/2015"
infowindow.setContent(content);
【问题讨论】:
标签:
google-maps
google-maps-api-3
google-maps-markers
【解决方案1】:
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<title>Info windows</title>
<style>
html, body {
height: 100%;
margin: 0;
padding: 0;
}
#map {
height: 100%;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
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 ="19/11/2015"
//this also works
// '<div>19/11/2015</div>'
//and this
// var date=new Date();
// var contentString =date.getDay()+'/'+date.getMonth()+'/'+date.getFullYear();
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);
});
}
</script>
<script async defer
src="https://maps.googleapis.com/maps/api/js?callback=initMap"></script>
</body>
</html>