当我打开时,页面是空白的。就地键我复制了我的钥匙,但它仍然不起作用。有人知道出了什么问题吗?我已经添加了html等。我不知道为什么每次打开时,页面都是空白的。没有错误或其他什么。
var gatePos = [{ gate: 1, x: 1177, y: 200 },{ gate: 2, x: 1109, y: 200 },{ gate: 3, x: 1042, y: 200 },{ gate: 4, x: 975, y: 200 },{ gate: 5, x: 908, y: 200 },{ gate: 6, x: 842, y: 200 },{ gate: 7, x: 774, y: 200 },{ gate: 8, x: 708, y: 200 },{ gate: 9, x: 641, y: 200 },{ gate: 10, x: 578, y: 200 }];
var gatePosValue = [{"gate":"8B","value":126},{"gate":"9B","value":268},{"gate":"10B","value":91},{"gate":"21B","value":9},{"gate":"24B","value":1},{"gate":"JC","value":48352},{"gate":"LOCALISER","value":22},{"gate":1,"value":34351},{"gate":2,"value":37855},{"gate":3,"value":38462},{"gate":4,"value":38126},{"gate":5,"value":40089},{"gate":6,"value":39295},{"gate":7,"value":36581},{"gate":8,"value":33908},{"gate":9,"value":31187},{"gate":10,"value":22915},{"gate":11,"value":5164},{"gate":12,"value":9533},{"gate":13,"value":6454},{"gate":14,"value":5003},{"gate":15,"value":1},{"gate":21,"value":19804},{"gate":22,"value":21239},{"gate":23,"value":17779},{"gate":24,"value":15213},{"gate":"-","value":37562}];
var gatePosResult = [];
for(var i = 0; i < gatePos.length; i++) {
gatePosResult[i] = {};
for(var key in gatePos[i]) {
if(gatePos[i].hasOwnProperty(key)) {
gatePosResult[i][key] = gatePos[i][key];
}
}
gatePosResult[i].value = null;
for(var j = 0; j < gatePosValue.length; j++) {
if(gatePosValue[j].gate === gatePosResult[i].gate) {
gatePosResult[i].value = gatePosValue[j].value;
break;
}
}
}
console.log(gatePosResult);
答案 0 :(得分:0)
您的代码存在一些问题:
<script>
标记<script>
标记initMap
作为回调函数的名称,但在您的代码中,函数名称为initialize
createMarker
未定义如果我修复了这些问题,则会正确加载地图。看看固定样本:
var map;
var service;
var infowindow;
function initialize() {
var pyrmont = new google.maps.LatLng(-33.8665433, 151.1956316);
map = new google.maps.Map(document.getElementById('map'), {
center: pyrmont,
zoom: 15
});
var request = {
location: pyrmont,
radius: '500',
type: ['restaurant']
};
service = new google.maps.places.PlacesService(map);
service.nearbySearch(request, callback);
}
function callback(results, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
for (var i = 0; i < results.length; i++) {
var place = results[i];
//createMarker(results[i]);
}
}
}
#map {
height: 100%;
}
html, body {
height: 100%;
margin: 0;
padding: 0;
}
<div id="map"></div>
<script src="https://maps.googleapis.com/maps/api/js?libraries=places&callback=initialize&key=AIzaSyDztlrk_3CnzGHo7CFvLFqE_2bUKEq1JEU" async defer></script>
您还可以在jsbin上看到示例:http://jsbin.com/cutomaxoxi/edit?html,output
我希望这有帮助!