错误类型错误:google.maps.Travelmode 未定义,即使已定义

问题描述 投票:0回答:1

我试图在我的项目中包含谷歌地图,尽管一切都应该是正确的,但我遇到了上面的错误。 如果我只是搜索一个位置,我到达那里,一切正常,但是当我尝试显示路线时,如谷歌文档所示,我收到错误 莫非谷歌不被识别?

ngOnInit() {
    this.loadMap();
  }

  loadMap() {
    Geolocation.getCurrentPosition()
      .then((resp) => {
        let latLng = new google.maps.LatLng(
          resp.coords.latitude,
          resp.coords.longitude
        );
        let mapOptions = {
          center: latLng,
          zoom: 15,
          mapTypeId: google.maps.MapTypeId.ROADMAP,
        };

        this.map = new google.maps.Map(
          this.mapElement.nativeElement,
          mapOptions
        );

        this.directionsRenderer.setMap(this.map);        
      })
      .catch((error) => {
        console.log("Error getting location", error);
      });
  }




calculateAndDisplayRoute() {
    this.directionsService.route(
      {
        origin: this.currentLatLng, //takes the current location
        destination: this.currentLatLng,
        waypoints: this.waypointArray,  
        optimizeWaypoints: true,
        travelMode: google.maps.Travelmode.DRIVING,//here's the problem
        drivingOptions: {
          trafficModel: "pessimistic",
        },
      },
      (response, status) => {
        if (status === "OK") {
          this.directionsRenderer.setDirections(response);
        }
      }
    );
  }
angular typescript google-maps ionic-framework
1个回答
0
投票

尝试改变: 旅行模式:google.maps.TravelMode.DRIVING

© www.soinside.com 2019 - 2024. All rights reserved.