Google maps api 3 将多段线捕捉到道路
因此,我尝试使用步行移动模式将多段线捕捉到道路上,目前我有一条工作多段线,当用户的地理位置移动时会更新,然后从旧位置删除旧的多段线,并从新原点到目标绘制一条新的多段线,但这是一条直线,就像乌鸦飞线一样Google maps api 3 将多段线捕捉到道路,google-maps-api-3,geolocation,polyline,Google Maps Api 3,Geolocation,Polyline,因此,我尝试使用步行移动模式将多段线捕捉到道路上,目前我有一条工作多段线,当用户的地理位置移动时会更新,然后从旧位置删除旧的多段线,并从新原点到目标绘制一条新的多段线,但这是一条直线,就像乌鸦飞线一样 function polyLine(myPos){ var start; if (!start){ start = geoMarker.position; }else{ start = myPos; } var end =
function polyLine(myPos){
var start;
if (!start){
start = geoMarker.position;
}else{
start = myPos;
}
var end = marker.position;
var pathCoords = [start, end];
var pathGo = new google.maps.Polyline({
path: pathCoords,
map: googleMap,
strokeColor: "#FF0000",
strokeOpacity: 0.7,
strokeWeight: 2
});
polyLineArray.push(pathGo);
}
我还尝试了通过其他线程找到的各种代码片段,但都没有成功。这就是我目前正在玩的东西
function calcDist(myPos) {
var start;
if (!start){
start = geoMarker.position;
}else{
start = myPos;
}
var end = marker.position;
var request = {
origin: start,
destination: end,
travelMode: google.maps.TravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK)
{
var steps = response.routes[0].legs[0].steps;
for(var step = 0; step < steps.length; step++)
{
polylineOptions = {
map: googleMap,
strokeColor: "#FF0000",
strokeOpacity: 0.7,
strokeWeight: 2,
path: steps[step].path
}
drawPoly = new google.maps.Polyline(polylineOptions);
}
drawPoly.getPath().push(ble);
}
});
}
身份的价值是什么?
var directionsDisplay;
var directionsService = new google.maps.DirectionsService();
function calcDist(myPos) {
var start;
if (!start){
start = geoMarker.position;
}else{
start = myPos;
}
var end = marker.position;
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.WALKING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}