我编写了这部分代码来在谷歌地图上显示方向 但目前我只有开始和结束位置 我想要有更多的站点并让路线尽可能好 如何输入多个停靠点? 到目前为止我就是这么做的
| Start | ||
|---|---|---|
| End |
方向组件
import { MapElementFactory } from "vue2-google-maps";
export default MapElementFactory({
name: "directionsRenderer",
ctr() {
return window.google.maps.DirectionsRenderer;
},
events: [],
mappedProps: {},
props: {
origin: { type: [Object, Array] },
destination: { type: [Object, Array] },
travelMode: { type: String },
},
afterCreate(directionsRenderer) {
console.log(1)
let directionsService = new window.google.maps.DirectionsService();
this.$watch(
() => [this.origin, this.destination, this.travelMode],
() => {
let { origin, destination, travelMode } = this;
if (!origin || !destination || !travelMode) return;
directionsService.route(
{
origin,
destination,
travelMode,
},
(response, status) => {
if (status !== "OK") return;
// eslint-disable-next-line no-debugger
//debugger
directionsRenderer.setDirections(response);
}
);
}
);
},
});
还有我的功能
setPlace(place) {
this.currentPlace = place;
},
addMarker(index) {
const marker = {
lat: this.currentPlace.geometry.location.lat(),
lng: this.currentPlace.geometry.location.lng(),
};
if (index === 0) this.startLocation = marker;
if (index === 1) this.endLocation = marker;
this.center = marker;
console.log(this.startLocation, this.endLocation)
},
所以到目前为止我一切都很好,一切都进展顺利,但我需要有更多的停留 从你所看到的我最后只有一个变量 我该如何继续? 我可以适应当前的代码吗?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号