javascript - Google Maps API 地图未显示
问题描述
所以也许这个错误非常幼稚,但我无法从 Google Maps API 加载 javascript 地图。
我想要完成的是使地图出现在按钮的右侧。但是……我不能。
这是我的代码。
HTML
<!DOCTYPE html>
<html>
<head>
<title>salgamos</title>
<link rel="stylesheet" href="{{ url_for('static', filename= 'css/en_corto.css') }}">
<script> </script>
</head>
<body>
<div class="domainhome">
<a href="/"><p>salgamos.com.mx</p></a>
</div>
<div class="flex-container">
<div class="left-bar">
<div>
<button class="adondequieresir"><p>¿a dónde quieres ir?</p></button>
</div>
<div>
<button class="agregarubicacion">
<p style="float: left;">¡agrega tu ubicación?</p>
</button>
</div>
<div>
<button class="personasunidas">
<p style="float: left;">(n) personas unidas</p>
</button>
</div>
</div>
<div class="right-bar">
<div id="map">
<script
src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAz5lUQhWbnyya36w_UiP-DjcdGj6Sfw&callback=initMap&libraries=&v=weekly"
async
></script>
</div>
</div>
</div>
JS
let map;
function initMap() {
map = new google.maps.Map(document.getElementById("map"), {
center: { lat: -34.397, lng: 150.644 },
zoom: 8,
});
}
我发现了类似的帖子,但事情要复杂得多,他们的回答只会让我感到困惑。如果有人可以帮助我,我将不胜感激。
解决方案
script
标签不应包裹在标签内div#map
。
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyAzw5lUQhZWbnyya36w_UiP-DjcdGj6Sfw&callback=initMap&libraries=&v=weekly" async></script>
推荐阅读
- c++ - 如何控制 C++ 控制台应用程序中的光标位置?
- ios - 无法构建项目 - libswiftAVFoundation.dylib:errSecInternalComponent 错误:任务失败,退出 1 信号 0
- html - 当particle.js库将画布附加到同一元素时,将元素居中在div中?
- reactjs - 异步任务和订阅时 ReactJS 内存泄漏
- javascript - nodejs:如何获取中间哈希值
- node.js - 使用批处理安装和配置 Protractor
- spring - 如何在 Spring Security preauthentication for siteminder 中验证 SM_USER 标头
- assertj - 来自 assertJ 的方法 anySatisfy 吞下实际的失败消息
- vba - 如何删除书签后插入的文本,以便我可以插入新文本
- perl - 是否可以优雅地重启 Mojolicious Minion 工人?