无法读取未定义的'角度误差'属性'panTo'

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了无法读取未定义的'角度误差'属性'panTo'相关的知识,希望对你有一定的参考价值。

我想在AGM地图上打开一个下拉菜单平移到某个城市。我这样做是通过在map组件中创建此方法,然后从View调用它:

public move = () => {
  alert("Test");
  const position = new google.maps.LatLng(  52.379189,  4.899431);
  this.map.panTo(position);
}

但是,我收到此错误消息:

无法读取未定义的'panTo'属性

有人可以指出出了什么问题吗?

import {Component, OnInit} from "@angular/core";
import { GoogleMapsAPIWrapper } from '@agm/core';
import { MapsAPILoader } from '@agm/core';
import { Observable, Observer } from 'rxjs';
import {GMapsService} from "./map.service";
import * as data from './inkomen.json';
import * as inbraakdata from '../../assets/output.json';
import * as data_latlon from './inkomen_latlon.json';
import * as inbraak_latlon from './output.json';
import {Http} from "@angular/http";
import 'rxjs/add/operator/map';
import {last} from "@angular/router/src/utils/collection";
import {DropdownModule} from "ngx-dropdown";
import {any} from "codelyzer/util/function";

@Component({
  selector : 'googlemap',
  templateUrl: 'maps.html',
  styleUrls: ['map.component.css']
})
export class GoogleMapsComponent implements OnInit{

arr = [];
arr2 = [];

jsonLatlon
map: any;
jsonData
result
inkomen
count = 0;
results: any;
pages =['abc','bca','pqr'];

constructor(private http: Http, private mapservice: GMapsService) {
  this.jsonData = data;
  this.jsonLatlon = data_latlon
  this.results = inbraak_latlon;
  this.result = inbraak_latlon;
}

ngOnInit(){
console.log(this.jsonData)
console.log(this.jsonLatlon.data)
console.log(this.results)
this.convert()


}

convert(){
  for(var i = 0; i < this.jsonData.length; i++){
  var spl = this.jsonData[i].wijk.split(" ");
  // this.getLatLon(this.jsonData[i].wijk, this.jsonData[i].stad, 
  this.jsonData[i].inkomen)
}
//this.showArr()
}





title: string = 'My first AGM project';
lat: number = 52.1941679;
lng: number = 4.6820146;

public move= () => {
  alert("test");
  const position = new google.maps.LatLng(52.379189,  4.899431);
  this.map.panTo(position);
}
}
答案

你的地图应该被初始化为方法.map,因为你已经在使用@agm/core你可以使用GoogleMapsAPIWrapper

进口

import { AgmCoreModule, GoogleMapsAPIWrapper, AgmInfoWindow, AgmDataLayer, CircleManager, AgmCircle } from '@agm/core';

并参考

 @ViewChild(GoogleMapsAPIWrapper) private gmapWrapper: GoogleMapsAPIWrapper;

你可以做到

this.gmapWrapper.panTo(position);

以上是关于无法读取未定义的'角度误差'属性'panTo'的主要内容,如果未能解决你的问题,请参考以下文章

AngularJS:无法读取未定义的属性'runner'

在遍历两个数组时无法读取未定义的属性'id':Angular

错误类型错误:无法读取未定义角度的属性“名称”

TypeError.无法读取未定义的'$__'属性。无法读取未定义的'$__'属性 - Mongoose v5.^。

TypeError:无法读取未定义的属性'spacing'

jqgrid treeGrid无法读取未定义的属性'rowIndex'