gpt4 book ai didi

javascript - "google is not defined"但包含 Google map API

转载 作者:行者123 更新时间:2023-12-03 04:19:05 27 4
gpt4 key购买 nike

我收到 ReferenceError google is not Defined。

我寻找解决方案,但没有任何帮助。

有什么想法吗?谢谢

编辑:相关代码

在index.html中:

    <script src="dojo/dojo-release-1.12.2/dojo/dojo.js"></script><!--Dojo Script-->
<script src="js/index.js"></script>

<link rel="stylesheet" href="css/bootstrap.min.css">
<link rel="stylesheet" href="css/index.css">
</head>
<!--Google Maps API-->
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=APICode&callback=initMap" async defer></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>

在index.js相关函数中,对谷歌地图进行一些操作:

function setMapOnAll(map) {
for (i = 0; i < markers.length; i++) {
markers[i].setMap(map);
}
}

function RefreshMap() {
location.reload();
initMap();
}

function initMap() {
var loggedin = localStorage.getItem("loggedIn");
if(loggedin == 0) {
var place = {lat: 52.558643, lng: 13.351725};
map = new google.maps.Map(document.getElementById('map'), {
zoom: 3,
center: place
});
}

else {
map = new google.maps.Map(document.getElementById('map'), {
//zoom: 3,
//center: place
});

GetLocations();

var geocoder = new google.maps.Geocoder();
document.getElementById("btnAdd").addEventListener("click", function() {
geocodeAddress(geocoder, map);
});
}
}

function GetLocationsDojo() {
require(["dojo/store/JsonRest"], function(JsonRest) {
var username = localStorage.getItem("username");
var session = localStorage.getItem("sessionID");

var store = new JsonRest ({
target: "http://localhost:8080/FAPServer/service/fapservice/getStandort",
headers: {
"Content-Type": "application/json"
}
});

locations = [];
for(i = 0; i < users.length; i++) {
store.get("?login=" + username + "&session=" + session + "&id=" + users[i]).then(
function(data) {
//console.log(data);

var breite = data.standort.breitengrad;
var laenge = data.standort.laengengrad;

var marker = new google.maps.Marker({
position: new google.maps.LatLng(breite, laenge),
map: map
});

infowindow = new google.maps.InfoWindow();
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(data.loginName);
infowindow.open(map, marker);
}
})(marker, i));

markers.push(marker);

//bounds map
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
bounds.extend(markers[i].getPosition());
}
map.fitBounds(bounds);
},
function(data) {}
);
}
});
}

最佳答案

async defer 延迟脚本的执行。它可能正在您的 index.js 脚本之后运行(并添加您尝试访问的变量)。

关于javascript - "google is not defined"但包含 Google map API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022632/

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