我的网页谷歌地图显示空白后,添加https到网站没有错误显示在控制台。我更改了与https相关的所有内容。将https url包含在google cloud控制台的api密钥凭据部分。将api url更改为https
仍然没有地图显示。
jQuery(function($) {
// Asynchronously Load the map API
var script = document.createElement('script');
script.src = "https://maps.googleapis.com/maps/api/js?callback=initialize&key=MY_API_KEY";
document.body.appendChild(script);
});
function attachClickHandler(marker){
google.maps.event.addListener(marker, 'click', function() {
var elem = $(marker.url);
console.log(marker.title);
$('html, body').animate({
scrollTop: elem.offset().top - 200
}, 1000 );
});
}
function initialize() {
var map;
var bounds = new google.maps.LatLngBounds();
var mapOptions = {
mapTypeId: 'roadmap'
};
map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
var markers = new Array();
<?php $i= 1; foreach($locations as $l): ?>
var marker = ['<?php echo $i; ?>', <?php echo $l->latitude; ?>, <?php echo $l->longitude; ?>, '#<?php echo $i; ?>'];
markers.push(marker);
<?php $i++; endforeach; ?>
var bounds = new google.maps.LatLngBounds();
var infowindow = new google.maps.InfoWindow();
for( i = 0; i < markers.length; i++ ) {
var position = new google.maps.LatLng(markers[i][1], markers[i][2]);
marker = new google.maps.Marker({
position: position,
map: map,
title: markers[i][0],
url: markers[i][3],
label: {color: '#fff', fontSize: '16px', fontWeight: '600', text: markers[i][0]}
});
bounds.extend(position);
attachClickHandler(marker);
}
map.fitBounds(bounds);
// Override our map zoom level once our fitBounds function runs (Make sure it only runs once)
var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
this.setZoom(8);
google.maps.event.removeListener(boundsListener);
});
}
发布于 2020-01-06 15:10:00
要排除与API密钥限制相关的问题,请尝试在Google云控制台中取消对API密钥的限制。如果使用不受限制的API键时,您的地图加载成功,则意味着您需要为您的域添加正确的HTTP referrers。例如:
如果您设置了API restrictions,请确保您允许JavaScript接口。
如果地图仍然无法加载无限制密钥,那么一定是其他原因,例如,您的计费帐户有问题,您向站点添加了错误的应用编程接口密钥,您的项目禁用了JavaScript应用编程接口……
如果在仔细检查所有这些之后问题仍然存在,您可能需要联系谷歌的Technical Support Team。
希望这能有所帮助!
https://stackoverflow.com/questions/59573709
复制