javascript - 如何在 Google Maps JavaScript API 中设置 API key ?

标签 javascript twitter-bootstrap google-maps-api-3

我正在使用 bootstrap 主题,但在添加 google map api 时遇到一些问题。 map 位于 javascript 文件中,如下所示:

google.maps.event.addDomListener(window, 'load', init);

function init() {

    var mapOptions = {

        zoom: 15,
        scrollwheel: false,
        center: new google.maps.LatLng(41.428005, -8.674701),

        styles: [
        {
...

    var mapElement = document.getElementById('map');

    var map = new google.maps.Map(mapElement, mapOptions);

    var marker = new google.maps.Marker({
        position: new google.maps.LatLng(41.428005, -8.674701),
        map: map,

在 html 中只有这个:

    <section class="map">
        <div id="map"></div>
    </section>

如何在此处添加 Api 键?

谢谢。

最佳答案

当您在网站上包含脚本时,Google Maps API 的 key 将作为查询参数包含在 URL 中。

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=API_KEY"></script>

关于javascript - 如何在 Google Maps JavaScript API 中设置 API key ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39512512/

相关文章:

javascript - 本地图设置了 'restriction' 选项时,map.fitBounds 的工作很奇怪

javascript - 性能 : NaCl vs Emscripten

javascript - 带有React Hooks的Firebase监听器

javascript - 如何将常量放入 React 组件中,并包装在 recompose 中

html - Bootstrap 4背景图像全高,导航栏无滚动

html - 在 div 中添加一个新元素会将其他元素向下和向外推出

javascript - 未捕获的语法错误 : Unexpected number when trying to read json data

javascript - 使用原型(prototype)构建原始 JS 'plugin'

html - 如何在angularjs中将样式封装到html模板中?

javascript - 无法显示和更新我的位置标记