我正在尝试将google maps包含在我的项目中,即使一切都正确,我也遇到了上述错误。 如果我只是搜索一个位置,我会到达那里,并且一切正常,但是当我尝试显示路线时,如google docs所示,我会收到错误消息 可能是以某种方式无法识别google吗?
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);
}
}
);
}