我試圖在標記從GeoJSON的文件加載到我的地圖,地圖加載罰款,但不斷收到錯誤...未捕獲的ReferenceError:谷歌沒有定義
Uncaught ReferenceError: google is not defined
在這條線...
google.maps.event.addDomListener(window, 'load', initialize);
我讀過這a few其他問題,而且大部分對付你需要怎樣包括谷歌地圖代碼之前映射腳本。我已經嘗試將它包含在我的頭部和地圖容器的正上方,但沒有運氣。地圖本身實際上是加載的,只是來自我的JSON文件的標記沒有。
HTML/JS代碼
<!DOCTYPE html>
<html>
<head>
<title>Game Industry Map</title>
<meta name="viewport" content="initial-scale=1.0">
<meta charset="utf-8">
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<link rel=StyleSheet href="css/style.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
</head>
<body>
<div class="navbar navbar-defualt navbar-fixed-top">
<a class="navbar-brand" href="#">Game Industry Map</a>
<div class="input-group">
<input type="text" class="form-control" placeholder="From Software, Naughty Dog, Bethesda Game Studios, BreakAway Games..." id="query" name="query" value="">
<div class="input-group-btn">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-search"></span></button>
</div>
</div>
</div>
<div class='content-container'>
<div id="map"></div>
<div id="company-info">
<!--To do...-->
</div>
</div>
<script type="text/javascript">
var map;
function initMap() {
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: 34.029602, lng: -118.452416},
zoom: 13
});
map.data.loadGeoJson('data.json');
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<script async defer src="https://maps.googleapis.com/maps/api/js?key=API_KEY_HERE&callback=initMap"
type="text/javascript"></script>
</body>
<footer>Created by <a href="#">My Name</a>.</footer>
</html>
GeoJSON的文件
{ "type": "FeatureCollection",
"features": [
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [34.019602, -118.452416]},
"properties": {
"company-logo": "images/activision.png",
"company-name": "Activision Publishing Inc",
}
},
{ "type": "Feature",
"geometry": {"type": "Point", "coordinates": [34.028230, -118.471270]},
"properties": {
"company-logo": "images/naughtydog.png",
"company-name": "Naughty Dog Inc",
}
}
]
}
可能重複的[(搜索選項不工作)未捕獲ReferenceError:谷歌未定義](http://stackoverflow.com/questions/35909352/search-option-not-working-uncaught-referenceerror-google-is-未定義) – geocodezip