【问题标题】:Google map route directions path color change with navigator moving on from one waypoint to another waypoint谷歌地图路线方向路径颜色随着导航器从一个航路点移动到另一个航路点而变化
【发布时间】:2015-08-17 09:53:36
【问题描述】:

我有这样的要求

Source,
waypoint 1,
waypoint 2,
waypoint 3,
Destination

我需要Sourcewaypoint 1的路径是一种颜色,waypoint 1waypoint 2是另一种颜色..分别。

在这里,我将整个路径显示为单(红色)颜色。但是当我们移动到下一个航点时,我需要更改不同的颜色

  mapSite.getDirection = function(latitudeValue, longitudeValue, waypts) {

        document.getElementById('directionsPanel').innerHTML = "";
        directionsDisplay = new google.maps.DirectionsRenderer({
        polylineOptions: {
        strokeColor: "red"
        }
    });
        var site = new google.maps.LatLng(latitudeValue, longitudeValue);

        var mapOptions = {
            center: site,
            zoom: 9,
            mapTypeId: google.maps.MapTypeId.ROADMAP

        }
        map = new google.maps.Map(document.getElementById('map'), mapOptions);
        mapSite.map = map;

            directionsDisplay.setMap(mapSite.map);
            var start = mapSite.latitude + "," + mapSite.longitude;                             
            var end = latitudeValue + "," + longitudeValue;

            var request = {
                origin: start,
                destination: end,
                waypoints: waypts,
                travelMode: google.maps.TravelMode.DRIVING
            };

            directionsService.route(request, function(response, status) {
                if (status == google.maps.DirectionsStatus.OK) {

                directionsDisplay.setDirections(response);
                   var route = response.routes[0];
                   directionsDisplay.setPanel(document.getElementById('directionsPanel'));

                } 
           });
   };

【问题讨论】:

    标签: javascript angularjs google-maps ionic


    【解决方案1】:

    我认为最简单的方法是多次调用方向api。比如Source->waypoint 1, waypoint 1->waypoint 2, waypoint 2->waypoint 3, waypoint 3->Destination...

    否则,您从回调函数directionsService.route(request, function(response, status) { 中获得的response 包含legssteps 和折线。你可以自己画出路线,而不是打电话给directionsDisplay.setDirections(response);

    请参阅official documentation 以了解更多回复格式的信息。

    【讨论】:

    • 有没有可能用方向路径改变navigator color
    猜你喜欢
    • 1970-01-01
    • 2014-03-29
    • 2012-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-29
    • 2019-04-08
    • 1970-01-01
    相关资源
    最近更新 更多