Here api 使用平均交通状况绘制路线图

Here api 使用平均交通状况绘制路线图,here-api,Here Api,早上好。我正试图让我的地图根据美国东部时间周一上午11:00的平均交通状况显示路线。我可以通过在服务URL中附加以下内容来使用calculateRoute服务实现这一点: &depart=".date('Y-m-d', strtotime('monday this week'))."T11:00:00-05 我用它来收集每个转弯的方向,但我也希望地图上的可视路线也能反映这一点。我对JS非常陌生,所以请原谅我的代码,我主要使用罐装的演示脚本,并对它们进行了修改,以满足我的需要。下面是我的

早上好。我正试图让我的地图根据美国东部时间周一上午11:00的平均交通状况显示路线。我可以通过在服务URL中附加以下内容来使用calculateRoute服务实现这一点:

&depart=".date('Y-m-d', strtotime('monday this week'))."T11:00:00-05

我用它来收集每个转弯的方向,但我也希望地图上的可视路线也能反映这一点。我对JS非常陌生,所以请原谅我的代码,我主要使用罐装的演示脚本,并对它们进行了修改,以满足我的需要。下面是我的地图代码。代码中也使用了PHP,但主要用于SQL数据和获取数据

<script>
    // Initialize the platform object:
    var platform = new H.service.Platform({
    'app_id': 'MY APP ID',
    'app_code': 'MY APP CODE'
    });

    // Obtain the default map types from the platform object
    var maptypes = platform.createDefaultLayers();

    // Obtain the default map types from the platform object:
    var defaultLayers = platform.createDefaultLayers();

    // Instantiate (and display) a map object:
    var map = new H.Map(
    document.getElementById('mapContainer'),
    defaultLayers.normal.traffic,
    {
    zoom: 10,
    center: { lat: 42.3314, lng: -83.0458 }
    }
    );
    // Create the default UI:
    var ui = H.ui.UI.createDefault(map, defaultLayers);
    // Enable the event system on the map instance:
    var mapEvents = new H.mapevents.MapEvents(map);

    // Add event listeners:
    map.addEventListener('tap', function(evt) {
    // Log 'tap' and 'mouse' events:
    console.log(evt.type, evt.currentPointer.type); 
    });

    // Instantiate the default behavior, providing the mapEvents object: 
    var behavior = new H.mapevents.Behavior(mapEvents);

    var routingParameters = {
    // The routing mode:
    'mode': 'fastest;truck;traffic:enabled',
    'waypoint0': 'geo!<?PHP echo $_GET['shipFrom']; ?>',

    // The end point of the route:
    'waypoint1': 'geo!<?PHP echo $geoCode; ?>',

    // To retrieve the shape of the route we choose the route
    // representation mode 'display'
    'representation': 'display'
    };

    // Define a callback function to process the routing response:
    var onResult = function(result) {
    var route,
    routeShape,
    startPoint,
    endPoint,
    linestring;
    if(result.response.route) {
    // Pick the first route from the response:
    route = result.response.route[0];
    // Pick the route's shape:
    routeShape = route.shape;

    // Create a linestring to use as a point source for the route line
    linestring = new H.geo.LineString();

    // Push all the points in the shape into the linestring:
    routeShape.forEach(function(point) {
    var parts = point.split(',');
    linestring.pushLatLngAlt(parts[0], parts[1]);
    });

    // Retrieve the mapped positions of the requested waypoints:
    startPoint = route.waypoint[0].mappedPosition;
    endPoint = route.waypoint[1].mappedPosition;

    // Create a polyline to display the route
    routeLine = new H.map.Polyline(linestring, {
    style: { lineWidth: 10 },
    arrows: { fillColor: 'white', frequency: 2, width: 0.8, length: 0.7 }
    });

    // Create a marker for the start point:
    var startMarker = new H.map.Marker({
    lat: startPoint.latitude,
    lng: startPoint.longitude
    });

    // Create a marker for the end point:
    var endMarker = new H.map.Marker({
    lat: endPoint.latitude,
    lng: endPoint.longitude
    });

    // Add the route polyline and the two markers to the map:
    map.addObjects([routeLine, startMarker, endMarker]);

    // Set the map's viewport to make the whole route visible:
    map.setViewBounds(routeLine.getBounds());
    }
};

// Get an instance of the routing service:
var router = platform.getRoutingService(); 

// Call calculateRoute() with the routing parameters,
// the callback and an error callback function (called if a
// communication error occurs):
router.calculateRoute(routingParameters, onResult,
    function(error) {
    alert(error.message);
    });
</script>

//初始化平台对象:
var平台=新的H.service.platform({
“应用程序id”:“我的应用程序id”,
“应用程序代码”:“我的应用程序代码”
});
//从平台对象获取默认贴图类型
var maptypes=platform.createDefaultLayers();
//从平台对象获取默认贴图类型:
var defaultLayers=platform.createDefaultLayers();
//实例化(并显示)地图对象:
变量映射=新的H.映射(
document.getElementById('mapContainer'),
默认层。正常。流量,
{
缩放:10,
中心:{纬度:42.3314,液化天然气:-83.0458}
}
);
//创建默认用户界面:
var ui=H.ui.ui.createDefault(映射,默认层);
//在映射实例上启用事件系统:
var mapEvents=新的H.mapEvents.mapEvents(映射);
//添加事件侦听器:
map.addEventListener('tap',函数(evt){
//记录“点击”和“鼠标”事件:
log(evt.type,evt.currentPointer.type);
});
//实例化默认行为,提供mapEvents对象:
var behavior=新的H.mapevents.behavior(mapevents);
var路由参数={
//路由模式:
“模式”:“最快;卡车;交通:已启用”,
“航路点0”:“geo!”,
//路线的终点:
“航路点1”:“geo!”,
//要检索路线的形状,请选择路线
//表示模式“显示”
“表示法”:“显示”
};
//定义回调函数以处理路由响应:
var onResult=函数(结果){
var路线,
routeShape,
起点,
终点,
线串;
if(结果、响应、路由){
//从响应中选择第一条路线:
route=result.response.route[0];
//拾取管线的形状:
routeShape=route.shape;
//创建要用作管线点源的线字符串
linestring=新的H.geo.linestring();
//将形状中的所有点推入线串:
routeShape.forEach(函数(点){
变量部分=点分割(',');
linestring.pushLatLngAlt(部分[0],部分[1]);
});
//检索请求航路点的映射位置:
起始点=路线。航路点[0]。地图位置;
端点=路线。航路点[1]。mappedPosition;
//创建多段线以显示管线
routeLine=新的H.map.多段线(线串{
样式:{lineWidth:10},
箭头:{fillColor:'white',频率:2,宽度:0.8,长度:0.7}
});
//为起点创建标记:
var startMarker=新的H.map.Marker({
纬度:起始点。纬度,
lng:startPoint.longitude
});
//为终点创建标记:
var endMarker=新的H.map.Marker({
纬度:端点。纬度,
液化天然气:终点经度
});
//将管线多段线和两个标记添加到地图:
addObjects([routeLine、startMarker、endMarker]);
//设置地图的视口以使整个路线可见:
setViewBounds(routeLine.getBounds());
}
};
//获取路由服务的实例:
var router=platform.getRoutingService();
//使用路由参数调用calculateRoute(),
//回调函数和错误回调函数(如果
//发生通信错误):
router.calculateRoute(路由参数、onResult、,
函数(错误){
警报(错误消息);
});

您可以在上述共享javascript代码中使用的routingParameters中添加离开参数

var routingParameters = {
// The routing mode:
'mode': 'fastest;truck;traffic:enabled',
'waypoint0': 'geo!<?PHP echo $_GET['shipFrom']; ?>',

// The end point of the route:
'waypoint1': 'geo!<?PHP echo $geoCode; ?>',

// To retrieve the shape of the route we choose the route
// representation mode 'display'
'representation': 'display',

//departure time
'departure' : '2018-10-22T11:00:00-05'
};
var路由参数={
//路由模式:
“模式”:“最快;卡车;交通:已启用”,
“航路点0”:“geo!”,
//路线的终点:
“航路点1”:“geo!”,
//要检索路线的形状,请选择路线
//表示模式“显示”
“表示”:“显示”,
//出发时间
“出发”:“2018-10-22T11:00:00-05”
};

您可以在上述共享javascript代码中使用的routingParameters中添加离开参数

var routingParameters = {
// The routing mode:
'mode': 'fastest;truck;traffic:enabled',
'waypoint0': 'geo!<?PHP echo $_GET['shipFrom']; ?>',

// The end point of the route:
'waypoint1': 'geo!<?PHP echo $geoCode; ?>',

// To retrieve the shape of the route we choose the route
// representation mode 'display'
'representation': 'display',

//departure time
'departure' : '2018-10-22T11:00:00-05'
};
var路由参数={
//路由模式:
“模式”:“最快;卡车;交通:已启用”,
“航路点0”:“geo!”,
//路线的终点:
“航路点1”:“geo!”,
//要检索路线的形状,请选择路线
//表示模式“显示”
“表示”:“显示”,
//出发时间
“出发”:“2018-10-22T11:00:00-05”
};

我也希望地图上的可视路线也能反映这一点-你能用例子详细解释一下吗?现在我的计算器使用的模式是:最快;卡车流量:启用以创建我的多段线。我希望能够使用出发时间来获得该时间段的历史交通状况。我还希望地图上的可视路线也能反映这一点-你能用例子详细解释一下吗?现在我的计算器使用的模式是:最快;卡车流量:启用以创建我的多段线。我希望能够利用出发时间了解当时的历史交通状况。谢谢。直到现在,我还没有回到这个项目上,只是看到了你的回应。我现在正在根据我的路线测试我的所有代码,看看它是否达到我期望的效果。谢谢。直到现在,我还没有回到这个项目上,只是看到了你的回应。我现在正在针对我的路由测试我的所有代码,看看它是否达到了我期望的效果。