javascript - 需要更改引导主题中的 Google API 密钥以使用谷歌地图
问题描述
我正在尝试让 Google 地图位置在我的新网站上运行。我正在使用 Bootstrap 主题,但我无法弄清楚如何更改其中的 API 密钥,因为我已经创建了一个,但是如果我检查开发控制台,总是使用旧的 API 密钥。
感谢帮助。
JavaScript
var google;
function init() {
// Basic options for a simple Google Map
// For more options see: https://developers.google.com/maps/documentation/javascript/reference#MapOptions
// var myLatlng = new google.maps.LatLng(40.71751, -73.990922);
var myLatlng = new google.maps.LatLng(40.69847032728747, -73.9514422416687);
// 39.399872
// -8.224454
var mapOptions = {
// How zoomed in you want the map to start at (always required)
zoom: 7,
// The latitude and longitude to center the map (always required)
center: myLatlng,
// How you would like to style the map.
scrollwheel: false,
styles: [
{
"featureType": "administrative.country",
"elementType": "geometry",
"stylers": [
{
"visibility": "simplified"
},
{
"hue": "#ff0000"
}
]
}
]
};
// Get the HTML DOM element that will contain your map
// We are using a div with id="map" seen below in the <body>
var mapElement = document.getElementById('map');
// Create the Google Map using out element and options defined above
var map = new google.maps.Map(mapElement, mapOptions);
var addresses = ['New York'];
for (var x = 0; x < addresses.length; x++) {
$.getJSON('http://maps.googleapis.com/maps/api/geocode/json?address='+addresses[x]+'&sensor=false', null, function (data) {
var p = data.results[0].geometry.location
var latlng = new google.maps.LatLng(p.lat, p.lng);
new google.maps.Marker({
position: latlng,
map: map,
icon: 'images/loc.png'
});
});
}
}
google.maps.event.addDomListener(window, 'load', init);
HTML
<script async defer src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&callback=initMap" type="text/javascript"></script>
<section class="ftco-section ftco-no-pt ftco-no-pb">
<div id="map" class="bg-white"></div>
</section>
解决方案
推荐阅读
- java - GDPR SDK 错误 [Android 工作室]
- regex - Word 的正则表达式之前没有一些特定的单词
- r - Ubuntu 18.04 上 RcppNumerical 和 RcppEigen 中的警告
- javascript - 动态html/php
- javascript - 在 div 中动态创建表
- java - 如何使用 textview 导航到另一个活动?
- c - RPC:分段错误(核心转储)
- php - Url Rewrite 在 apache 服务器 godaddy 上不起作用
- r - 在 R 中结合 data.frame 和 data.frames 列表,没有公共变量
- c# - TCP 客户端不会从所有客户端接收数据,而是只接收一个客户端的数据