我从Google电子表格中导入地址,然后将其放在Google地图上。位置(纬度和经度)存储在变量中。我遍历所有条目并创建标记。 Google Spreadsheet和网站之间的连接有效,但仅显示第一个条目。因此,循环似乎是一个问题。
首先,我认为_location.latitude/_location.longitude
中的值有问题,我尝试在其中设置.value,但这不是问题。
循环位于_setLocations
函数中,从我的搜索看来,var _bounds
或_bounds.extend
似乎有问题
_createGoogleMap: function(_mapID){
var _this = this;
var _locations = [];
var _sheetUrl = 'https://sheets.googleapis.com/v4/spreadsheets/xxxxxxxxxxxxxxxxxxx/values/Sheet1!A2:U?key=xxxxxxxxxxxxxxxxxxxxxx';
var _map = new google.maps.Map(document.getElementById(_mapID),this._mapProp);
$.getJSON(_sheetUrl,function(data) {
$(data.values).each(function() {
var _location = {};
_location.latitude = parseFloat(this[8]);
_location.longitude = parseFloat(this[9]);
_locations.push(_location);
});
_this._setLocations(_map,_locations);
});
},
_setLocations: function(_map,_locations) {
var _this = this;
var _bounds = new google.maps.LatLngBounds();
var _infowindow = new google.maps.InfoWindow({
content: "Content String"
});
for (var i = 0; i < _locations.length; i++) {
var _new_marker = _this._createMarker(_map,_locations[i],_infowindow);
_bounds.extend(_new_marker._position);
}
_map.fitBounds(_bounds);
},
当我'console.log(_locations);'在循环之前, 我得到了所有地址,但是在循环之后我什么也没得到 不再。
任何帮助表示赞赏。