行人和自行车路线要长于汽车路线

时间:2019-06-11 12:46:24

标签: here-api

我正在使用Here Maps API计算路线,其中大多数用于自行车和行人。 我发现非常奇怪的是,有时汽车路线比行人或自行车路线小得多。 我有一个附件示例(图像显示行人和汽车路线)。 这是从adres: Steenweg 66,9473登德勒约,比利时 至 比利时登德勒约(Genderen Moortelhoek)17,格鲁登(Grooten)Moortelhoek 17,17

如果我在Google Maps中也做同样的事情,那没关系...

任何建议...

最好的问候 巴特

代码:

<html>
  <head>
    <meta name="viewport" content="initial-scale=1.0, width=device-width" />
    <script src="http://js.api.here.com/v3/3.0/mapsjs-core.js" type="text/javascript" charset="utf-8"></script>
    <script src="http://js.api.here.com/v3/3.0/mapsjs-service.js" type="text/javascript" charset="utf-8"></script>
      <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-ui.js"></script>
    <script type="text/javascript" src="https://js.api.here.com/v3/3.0/mapsjs-mapevents.js"></script>
    <link rel="stylesheet" type="text/css" href="https://js.api.here.com/v3/3.0/mapsjs-ui.css?dp-version=1526040296" />
  </head>

  <body>
    <div id="mapContainer" style="width: 67%; height: 100%; float:left; border: 1px solid black"></div>
    <div id="panel" style="position:absolute; width:29%; left:67%; height:97%; background:inherit; " ></div>

    <script>
      var url = window.location.toString();
      var appid = '';
      var appcode = '';
      var typeaction = '';
      var formatadres = '';
      var fromadres = '';
      var toadres = '';
      var fromlatitude = '';
      var fromlongitude = '';
      var tolatitude = '';
      var tolongitude = '';
      var minrelevance = 0;
      var routemode = '';
      // Create the parameters for the routing request:
      // var routingParameters = {
      //   // The routing mode:
      //   mode: 'fastest;car',
      //   // The start point of the route:
      //   waypoint0: fromlatlng,
      //   // The end point of the route:
      //   waypoint1: tolatlng,
      //   // To retrieve the shape of the route we choose the route
      //   representation: 'display',
      //   routeattributes : 'waypoints,summary,shape,legs',
      // };

      // omzetten van tijd in minuten en seconden
      Number.prototype.toMMSS = function () {
        return  Math.floor(this / 60)  +' min. '+ (this % 60)  + ' sec.';
      }

      //get the parameters from url
      url.match(/\?(.+)$/);
      var params = RegExp.$1;
      readUrlParameters(params);

      // Initialize the platform object:
      var platform = new H.service.Platform({
          'app_id': appid,
          'app_code': appcode
          });
      var defaultLayers = platform.createDefaultLayers();
      var map = new H.Map(
            document.getElementById('mapContainer'),
            defaultLayers.normal.map, {
              center: {lat: 50.8121, lng: 4.2190},
              zoom: 9
        });
      var routeInstructionsContainer = document.getElementById('panel');  
      var behavior = new H.mapevents.Behavior(new H.mapevents.MapEvents(map));
      var ui = H.ui.UI.createDefault(map, defaultLayers);
      // Get an instance of the routing service:
      var router = platform.getRoutingService();
      // Get an instance of the geocoding service:
      var geocoder = platform.getGeocodingService();

      // CALLBACK FUNCTIONS 
      // Define a callback function to process the reverse geocoding response:
      var onShowlatlong = function(result) {
        var location = result.Response.View[0].Result[0];

        // Create an InfoBubble at the returned location with
        // the address as its contents:
        // ui.addBubble(new H.ui.InfoBubble({
        //   lat: location.Location.DisplayPosition.Latitude,
        //   lng: location.Location.DisplayPosition.Longitude
        //   }, { content: '<p class="H_ib_body">' + location.Location.Address.Label + '</p>'}));
        // Create a marker for the point:
        var adressMarker = new H.map.Marker({
            lat: location.Location.DisplayPosition.Latitude,
            lng: location.Location.DisplayPosition.Longitude
          });

        // Add the route polyline and the two markers to the map:
        map.addObjects([adressMarker]);

        map.setCenter({lat: location.Location.DisplayPosition.Latitude, lng: location.Location.DisplayPosition.Longitude});
        map.setZoom(17);  
      };

      // Define a callback function to process the geocoding response:
      var onShowadress = function(result) {
        var locations = result.Response.View[0].Result,
          position,
          marker;

        // alert(result.Response.View[0].Result[0].Relevance * 100);
        if (result.Response.View[0].Result[0].Relevance * 100 < minrelevance) {
           alert("Adres niet gevonden");
           return;
        }  
        // Add a marker for each location found
        for (i = 0;  i < locations.length; i++) {
        position = {
          lat: locations[i].Location.DisplayPosition.Latitude,
          lng: locations[i].Location.DisplayPosition.Longitude
        };

        // alert(result.Response.View[0].Result[0].MatchLevel);
        document.getElementById("fromLatitudechar").value = position.lat;
        document.getElementById("fromLongitudechar").value = position.lng;
        document.getElementById("fromRelevance").value = result.Response.View[0].Result[0].Relevance;

        marker = new H.map.Marker(position);
        map.addObject(marker);
        map.setCenter({lat: position.lat, lng: position.lng});
        map.setZoom(17);  
        }
      };

      // Define a callback function to process the calcroutlatlng:
      var onCalcRoutelatlng = function(result) {
        var route,
          routeShape,
          startPoint,
          endPoint,
          linestring;

        if (typeof result.response === 'undefined') {
          alert("Route niet gevonden");
          return;
        }
        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:
        var routeLine = new H.map.Polyline(linestring, {
          style: { strokeColor: 'blue', lineWidth: 5 },
          arrows: { fillColor: 'white', frequency: 5, width: 1, length: 1 }
        });

        // 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());

        addWaypointsToPanel(route.waypoint);
        addManueversToPanel(route);
        addSummaryToPanel(route.summary);
        document.getElementById("distance").value = route.summary.distance;
        //alert(route.summary.distance);
        //alert(route.summary)
        // toonAfstand(route.summary);
        }
      };

      // END CALLBACK FUNCTIONS

      // functie aanroepen om taal naar het Nederlands te zetten
      switchMapLanguage(map , platform);

      switch(typeaction){
        case 'showadres': {
          if (formatadres == "latlng") {
            var reverseGeocodingParams = {
              // prox: '51.20866,3.18413',
              prox: fromadres,
              mode: 'retrieveAddresses',
              maxresults: 1
              };
            geocoder.reverseGeocode(reverseGeocodingParams, onShowlatlong, function(e) {
              alert(e);
            });
          }
          else {
            var geocodingParams = {
                searchText: fromadres
              };
            // Call the geocode method with the geocoding parameters,
            // the callback and an error callback function (called if a
            // communication error occurs):
            geocoder.geocode(geocodingParams, onShowadress, function(e) {
              alert(e);
            });
          }
          break;
        };
        case 'showpin': {
          var adressMarker = new H.map.Marker({
            lat: fromlatitude,
            lng: fromlongitude
          });

          // Add the route polyline and the two markers to the map:
          map.addObjects([adressMarker]);

          map.setCenter({lat: fromlatitude, lng: fromlongitude});
          map.setZoom(17);  
          break;
        }

        // mode=shortest;car;traffic:disabled        
        case 'calcroutelatlng': {
          var fromlatlng = 'geo!' + fromlatitude + ',' + fromlongitude;
          var tolatlng = 'geo!' + tolatitude + ',' + tolongitude;
          var routingParameters = {
            // The routing mode:
            mode: routemode,
            // The start point of the route:
            waypoint0: fromlatlng,
            // The end point of the route:
            waypoint1: tolatlng,
            // To retrieve the shape of the route we choose the route
            representation: 'display',
            routeattributes : 'waypoints,summary,shape,legs',
            maneuverattributes: 'direction,action',
            language: 'nl-nl'
          };
          router.calculateRoute(routingParameters, onCalcRoutelatlng,
            function(error) {
              alert(error.message);
            });
          break;
        }
      };

      // functie om map in het nederlands te krijgen, dit wordt aangeroepen bij het laden van de map
      function switchMapLanguage(map, platform){
        var mapTileService = platform.getMapTileService({type: 'base'}),
          // Our layer will load tiles from the HERE Map Tile API
          dutchMapLayer = mapTileService.createTileLayer(
            'maptile',
            'normal.day',
            512,
            'png8',
            {lg: 'DUT'}
            );
          map.setBaseLayer(dutchMapLayer);
          ui.removeControl('mapsettings');
          }

      function readUrlParameters (urlParameters) {
        // split up the query string and store in an
        // associative array
        var urlParameters = urlParameters.split("&");
        var queryStringList = {};

        for(var i=0;i<urlParameters.length;i++)
        {
        var tmp = urlParameters[i].split("=");
          queryStringList[tmp[0]] = unescape(tmp[1]);
        }
        appid = queryStringList["appid"];
        appcode = queryStringList["appcode"];
        typeaction = queryStringList["action"];
        formatadres = queryStringList["formatadres"];
        fromadres = queryStringList["adress1"];
        minrelevance = queryStringList["minrelevance"];
        fromlatitude = queryStringList["fromlat"];
        fromlongitude = queryStringList["fromlng"];
        tolatitude = queryStringList["tolat"];
        tolongitude = queryStringList["tolng"];
        routemode = queryStringList["routemode"];
      }

      function addWaypointsToPanel (waypoints){
        var nodeH3 = document.createElement('h5'),
          waypointLabels = [],
          i;
        nodeH3.style.marginLeft = '1%';
        for (i = 0;  i < waypoints.length; i += 1) {
          waypointLabels.push(waypoints[i].label)
        }

        nodeH3.textContent = waypointLabels.join(' - ');
        routeInstructionsContainer.innerHTML = '';
        routeInstructionsContainer.appendChild(nodeH3);
      }

      function addManueversToPanel(route){
        var nodeOL = document.createElement('ol'),
          i,
          j;

        nodeOL.style.fontSize = 'small';
        nodeOL.style.marginLeft ='2%';
        nodeOL.style.marginRight ='2%';
        nodeOL.className = 'directions';

          // Add a marker for each maneuver
        for (i = 0;  i < route.leg.length; i += 1) {
          for (j = 0;  j < route.leg[i].maneuver.length; j += 1) {
            // Get the next maneuver.
            maneuver = route.leg[i].maneuver[j];

            var li = document.createElement('li'),
              // spanArrow = document.createElement('span'),
              spanInstruction = document.createElement('span');
            // spanArrow.className = 'arrow '  + maneuver.action;
            spanInstruction.innerHTML = maneuver.instruction;
            //li.appendChild(spanArrow);
            li.appendChild(spanInstruction);

            nodeOL.appendChild(li);
          }
        }
        routeInstructionsContainer.appendChild(nodeOL);
      }

      function addSummaryToPanel(summary){
        var summaryDiv = document.createElement('div'),
        content = '';
        content += '<b>Totale afstand</b>: ' + (summary.distance / 1000)  + 'km. <br/>';
        content += '<b>Reistijd</b>: ' + summary.travelTime.toMMSS() + ' (huidig verkeer)';


        summaryDiv.style.fontSize = 'small';
        summaryDiv.style.marginLeft ='2%';
        summaryDiv.style.marginRight ='2%';
        summaryDiv.innerHTML = content;
        routeInstructionsContainer.appendChild(summaryDiv);

      }
    </script>

    <form method="post">
      <input name="fromLatitudechar" id="fromLatitudechar" type="hidden">
      <input name="fromLongitudechar" id="fromLongitudechar" type="hidden">
      <input name="toLatitudechar" id="toLatitudechar" type="hidden">
      <input name="toLongitudechar" id="toLongitudechar" type="hidden">
      <input name="fromRelevance" id="fromRelevance" type="hidden">
      <input name="toRelevance" id="toRelevance" type="hidden">
      <input name="distance" id="distance" type="hidden">
    </form>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

我们使用路由api检查了两个地址之间的路由结果。

从Steenweg向Hertstraat左转有一个限制。该位置的纬度为50.906072,4.054588。

我们将检查限制是否在现实世界中退出并更新。

谢谢!