【发布时间】:2020-09-12 22:32:40
【问题描述】:
在我的应用程序中加载了几张地图,我在页面中没有发生的错误是在页面的第一次加载时它没有加载地图,但是当我加载地图时执行无限滚动时,这个页面加载了一个重定向它的 Angular 路由器。
我首先将信息加载到 ngOnInit(): void {} 中,最后执行此函数以加载地图。
我尝试使用 navParams 以不同的方式将信息传递给他,但它仍然不起作用,我还设置了 setTimeout basatante 时间,以防是时候加载但它仍然不起作用
这是我的代码
async getPublications(page, adding = false) {
const loading = await this.loading.create();
loading.present();
this._publicationService.getPublicationsUser(this.token,this.id ,page).subscribe(
response => {
console.log(response);
if (response.publications) {
this.coords = [];
this.total = response.total_items;
this.pages = response.pages;
this.items_per_page = response.items_per_page
if (!adding) {
this.publications = response.publications
for (let i = 0; i < this.publications.length; i++) {
let cord = this.publications[i].location.split(',');
let object = {
lat: cord[0], lng: cord[1], zoom: 15
}
this.coords.push(object);
}
setTimeout(() => {
this.initialize();
loading.dismiss();
}, 3000);
} else {
var arrayA = this.publications;
var arrayB = response.publications;
this.publications = arrayA.concat(arrayB);
console.log(this.publications)
for (let i = 0; i < this.publications.length; i++) {
let cord = this.publications[i].location.split(',');
let object = {
lat: cord[0], lng: cord[1], zoom: 15
}
this.coords.push(object);
}
setTimeout(() => {
this.initialize();
loading.dismiss();
}, 3000);
}
} else {
loading.dismiss();
}
},
async error => {
}
)
}
initialize() {
for (var i = 0, length = this.coords.length; i < length; i++) {
var point = this.coords[i];
var latlng = new google.maps.LatLng(point.lat, point.lng);
this.maps[i] = new google.maps.Map(document.getElementById('map' + (i)), {
zoom: point.zoom,
center: latlng,
zoomControl: false,
mapTypeControl: false,
scaleControl: false,
streetViewControl: false,
rotateControl: false,
fullscreenControl: false,
gestureHandling: 'none',
});
this.markers[i] = new google.maps.Marker({
position: latlng,
map: this.maps[i]
});
}
}
<div id="{{'map'+i}}" style="max-width:500px; height:300px"></div>
【问题讨论】:
标签: angular google-maps ionic-framework