我正在尝试使用 directionService
绘制从A点到B点的折线 .
我跟随最好的法庭 .
首先创建 Map ,下载插件插件@ ionic-native / google-maps
let mapOptions: GoogleMapOptions = {
camera: {
target: {
lat: 0,
lng: 0
},
zoom: 16, //14
bearing: 0
},
controls: {
compass: true,
myLocationButton: true,
mapToolbar: false
},
gestures: {
scroll: true,
tilt: true,
rotate: false,
zoom: true
},
};
this.message = 'map_is_ready';
let mapElement: HTMLElement = document.getElementById('map');
this.map = GoogleMaps.create(mapElement, mapOptions);
this.map.setVisible(true);
之后,当点击这些点执行一个应该构建我创建它的点的路径的函数时,获取一些点放在 Map 上 . 功能是这种形式:
setPolylineDirectionMyAndPoint(start, end) {
const request = { // Novo objeto google.maps.DirectionsRequest, contendo:
origin: start, // origem
destination: end, // destino
travelMode: google.maps.TravelMode.WALKING // meio de transporte, nesse caso, apé
};
this.directionsService.route(request, function (result, status) {
if (status == google.maps.DirectionsStatus.OK) {
const plyPath = [];
const legs = result.routes[0].legs;
for (let i = 0; i < legs.length; i++) {
var steps = legs[i].steps;
for (let j = 0; j < steps.length; j++) {
var nextSegment = steps[j].path;
for (let k = 0; k < nextSegment.length; k++) {
plyPath.push(nextSegment[k]);
}
}
}
const polyline = new google.maps.Polyline({
path: plyPath,
strokeColor: '#0032e9',
strokeWeight: 8
});
}
});
}
我做了这个尝试,并尝试通过插件本身创建:
let polylineOptions = {
points: plyPath,
'color': '# 0032e9',
'width': 8,
'geodesic': true,
};
this.map.addPolyline (polylineOptions) .then ((polyline: Polyline) => {
});
但它给出了一个错误,说 addPolyline
不是一个函数,我创建了几个 polylines
并且一切都运行正常,但为此它无法正常工作 . 我知道,对于插件本身我不能这样做但是我想要获得积分并且我自己在 Map 上设置这些点 .
如何解决这个问题呢?我需要从我到我点击的点的路径 .
1 回答