gpt4 book ai didi

javascript - 谷歌地图每次都无法正确加载

转载 作者:行者123 更新时间:2023-11-28 12:32:37 26 4
gpt4 key购买 nike

有时,Google map 无法正确加载,并且不允许插入标记:

enter image description here

这是我创建 map 的代码:

var companyCreateMap;
var companyCreateMapInitialZoom = 7;

function companyLoadInitialMap()
{
companyCreateGeocoder = new google.maps.Geocoder();

var companyCreateInitialLocation = new google.maps.LatLng(companyCreateMapInitialCenterLat, companyCreateMapInitialCenterLng);

var companyCreateMapOptions = {
center: companyCreateInitialLocation,
zoom: companyCreateMapInitialZoom,
mapTypeId: google.maps.MapTypeId.ROADMAP
}

companyCreateMap = new google.maps.Map(document.getElementById(companyCreateMapCanvas), companyCreateMapOptions);

google.maps.event.addListener(companyCreateMap, 'click', updateMarkerCoordenatesOnClick);

companyCreateGetUserLocation();
}

function companyCreateGetUserLocation()
{
if (navigator.geolocation)
{
browserSupportFlag = true;

navigator.geolocation.getCurrentPosition(function (companyCreatePosition)
{
var companyCreateCenterLocation = new google.maps.LatLng(companyCreatePosition.coords.latitude, companyCreatePosition.coords.longitude);

companyCreateMap.setCenter(companyCreateCenterLocation);
companyCreateMap.setZoom(17);
companyCreateMarker = new google.maps.Marker({ position: companyCreateCenterLocation, map: companyCreateMap, animation: google.maps.Animation.DROP });
},
function (error)
{
// User did not accept to give location
//handleNoGeolocation(browserSupportFlag, error);
});
}
// Browser doesn't support Geolocation
else
{
browserSupportFlag = false;
//handleNoGeolocation(browserSupportFlag);
}
}

这种情况并不是每次都会发生,只是偶尔发生,而且我在控制台中没有收到任何错误。

有什么想法吗?

最佳答案

淡入完成后,您需要触发 map 调整大小。

$('#map-canvas').fadeIn(200, function() {

// Trigger a map resize
google.maps.event.trigger(map, 'resize');
});

JSFiddle demo

关于javascript - 谷歌地图每次都无法正确加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20571373/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com