Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 角度9&;google地图标记器单击事件无法正常工作_Angular_Google Maps_Google Maps Api 3_Google Maps Markers - Fatal编程技术网

Angular 角度9&;google地图标记器单击事件无法正常工作

Angular 角度9&;google地图标记器单击事件无法正常工作,angular,google-maps,google-maps-api-3,google-maps-markers,Angular,Google Maps,Google Maps Api 3,Google Maps Markers,下面是我启动映射并添加集群和标记的代码。一切正常,但标记单击行为异常,就像事件立即触发并命中API一样,但全局变量会在几秒钟后,几分钟后更新 renderMap() { window['initMap'] = () => { this.loadMap(); }; if (!window.document.getElementById('google-map-script')) { const s = window.document.cr

下面是我启动映射并添加集群和标记的代码。一切正常,但标记单击行为异常,就像事件立即触发并命中API一样,但全局变量会在几秒钟后,几分钟后更新

  renderMap() {

    window['initMap'] = () => {
      this.loadMap();
    };
    if (!window.document.getElementById('google-map-script')) {
      const s = window.document.createElement('script');
      s.id = 'google-map-script';
      s.type = 'text/javascript';
      s.src = 'https://maps.googleapis.com/maps/api/js?key=' + environment.GOOGLE_MAP_API_KEY + '&callback=initMap';

      window.document.body.appendChild(s);
    } else {
      this.loadMap();
    }
  }

  loadMap() {
    const map = new window['google'].maps.Map(this.mapElement.nativeElement, {
      center: {lat: this.center.lat, lng: this.center.lng},
      zoom: this.zoom
    });
    const markers = this.markers.map((location, i) => {
      const marker = new google.maps.Marker({
        position: {lat: location.lat, lng: location.lng},
        label: location.label,
        icon: 'assets/img/marker_.png',
        title: location.title,
        clickable: true
      });

      marker.addListener('click', () => {
        const m = location;
        this.customer = m;
        this.showLocation = true;
        this.loading = true;
        this.center = {
          lat: m.lat,
          lng: m.lng
        };
        this.companyService.company(m.company_id).subscribe((company: any) => {
          this.company = company;
          this.loading = false;
        }, error => {
          this.loading = false;
          console.log(error);
        });
      });
      return marker;
    });

    const markerCluster = new MarkerClusterer(map, markers,
      {imagePath: 'https://developers.google.com/maps/documentation/javascript/examples/markerclusterer/m'});

  }

  ngOnInt(){
    this.renderMao();
  }

您可能需要在NgZone中运行
单击
回调

constructor(private zone: NgZone)


marker.addListener('click', () => {
    this.zone.run(() => { 
     ...
});

您可能需要在NgZone中运行
单击
回调

constructor(private zone: NgZone)


marker.addListener('click', () => {
    this.zone.run(() => { 
     ...
});