Angular-google-maps panTo不起作用

时间:2018-01-06 02:01:50

标签: angular typescript bootstrap-4 angular-google-maps

嗨,所以我有一些角度/引导代码,试图平移到位置。我认为问题出在GoogleMapsAPI Wrapper的不同实例中。顺便说一句。缩放和打印圆圈也不起作用。

  constructor(private _service: MapService,
              private route: ActivatedRoute,
              private wrapper: GoogleMapsAPIWrapper) {
  }

  show(measurement: MeasurementDTO) {
    const latlng = new google.maps.LatLng(measurement.latLng.lat, measurement.latLng.lng());
    console.log(latlng.lat);
    this.map.panTo(latlng);
  }

这是部分观点。测量来自于表格,但我认为它无用的信息。

  <agm-map style="height: 600px" [latitude]="1" [longitude]="1" [usePanning]="true">
    <agm-marker-cluster [imagePath]="'https://googlemaps.github.io/js-marker-clusterer/images/m'">
      <agm-marker
        *ngFor="let measurement of measurements"
        [latitude]="measurement.latLng.lat"
        [longitude]="measurement.latLng.lng">
      </agm-marker>
    </agm-marker-cluster>
  </agm-map>
        <button (click)="show(measurement)">Show</button>

更新6.12.2018

我通过在组件中添加 map 来解决这个问题:

  map: any;

  setMap(map) {
    console.log(map);
    this.map = map;
  }

这个在html中的onReady:

<agm-map #mapka style="height: 600px" [latitude]="52.279986" [longitude]="17.35229389999995" [usePanning]="true"
               (mapReady)="setMap($event)">

0 个答案:

没有答案