我试图在我的项目中包含谷歌地图,尽管一切都应该是正确的,但我遇到了上面的错误。 如果我只是搜索一个位置,我到达那里,一切正常,但是当我尝试显示路线时,如谷歌文档所示,我收到错误 莫非谷歌不被识别?
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);
}
}
);
}
尝试改变: 旅行模式:google.maps.TravelMode.DRIVING