【发布时间】:2020-08-07 11:14:04
【问题描述】:
我已经(无休止地)搜索了论坛,尝试了我找到的所有内容,但没有任何效果。我有以下代码。我希望能够单击其中一个标记并弹出一个带有从相应 JSON 派生的唯一内容的 InfoWindow 弹出窗口,以便该窗口具有位置、日期时间和详细信息,并且我可以使用不同的 html/css 来定位它们。没有任何效果。有什么帮助吗?
HTML
<head>
<title>Data Layer: Simple</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link href="style.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="mymap"></div>
<script type="text/javascript" src="script.js"></script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=REDACTED&callback=initMap">
</script>
</body>
</html>
CSS
@charset "UTF-8";
#mymap {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
JAVASCRIPT
var ufomap;
var infowindow = new google.maps.InfoWindow();
function initMap() {
ufomap = new google.maps.Map(document.getElementById('mymap'), {
zoom: 4,
center: {lat:37.0902,lng:-95.7129}
});
ufomap.data.loadGeoJson('json.geojson');
}
JSON
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"Location":"Greensburg, PA",
"Date-Time":"1969-01-01T10:00:00",
"Shape”:”Circle”,
"Details":"Possible contact with Visitor as a child When I was 2 to 4 years old",
"Latitude":"40.33569572",
"Longitude":"-79.55026848"
},
"geometry":{
"type":"Point",
"coordinates":[
-79.550268,
40.335696
]
}
},
{
"type":"FeatureCollection",
"features":[
{
"type":"Feature",
"properties":{
"Location”:”Smithtown, PA",
"Date-Time":"1979-01-01T10:00:00",
"Shape”:”Square”,
"Details”:”Bright lights flashing“,
"Latitude":"44.33569572",
"Longitude":"-78.55026848"
},
"geometry":{
"type":"Point",
"coordinates":[
-78.550268,
44.335696
]
}
}
【问题讨论】:
标签: javascript json api google-maps google-maps-api-3