2

最近、アプリケーションの出発地と目的地の間に「ウェイポイント」があるDirectionsServiceを使用すると、視覚的に意味のないこれらの「ジグザグ」ルートが返されるようになりました。

見た目はすべて順調ですが、7番目のウェイポイントの後のどこかで、ルートは劇的なジグザグに前のウェイポイントに戻り、適切なパスに戻ろうとしているように見えます。

私が言おうとしていることを示す画像を添付し、物事がうまくいかない点を赤で指摘しました。さらに、以下のサンプルコードを含め、問題の実用的なデモンストレーションをここに投稿しました。

http://dev.anytraq.com:8080/test.html(作業バージョン)

矢印でマークされた問題

ここの誰かがそのような問題に遭遇したのか、それとも何が起こっているのかを明らかにすることができるのだろうかと私は思っていました。以下に示すように、コードは非常に単純です。基本的に、起点と終点のLatLngオブジェクト、およびその間の8つのウェイポイントを定義し、DirectionsServiceに送信します。

私は頭に浮かぶかもしれないありとあらゆる提案に感謝します、私は完全に困惑しています。

<!DOCTYPE html> 
<html> 
  <head> 
    <title>ZigZagged Directions Example</title> 

    <meta charset="UTF-8"> 
    <style type="text/css"> 
      html, body, #map_canvas {
        margin: 0;
        padding: 0;
        height: 100%;
      }
    </style> 
    <script type="text/javascript"
        src="https://maps.googleapis.com/maps/api/js?sensor=false"></script> 
    <script type="text/javascript"> 
      var map;
      function initialize() {

        // map options
        var myOptions = {
          zoom: 8,
          center: new google.maps.LatLng(-34.397, 150.644),
          mapTypeId: google.maps.MapTypeId.ROADMAP
        };

        // the map
        map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);

        // directions service
        directionsService = new google.maps.DirectionsService();

        // Define our origin position, the start of our trip.
        originPosition = new google.maps.LatLng('37.66258', '-121.87058');

        // Define 8 waypoints to place between the origin and the destination
        waypoint1 = new google.maps.LatLng('37.65638', '-121.87750');
        waypoint2 = new google.maps.LatLng('37.64333', '-121.88174');
        waypoint3 = new google.maps.LatLng('37.63676', '-121.88447');
        waypoint4 = new google.maps.LatLng('37.60746', '-121.87343');
        waypoint5 = new google.maps.LatLng('37.57868', '-121.87702');
        waypoint6 = new google.maps.LatLng('37.56368', '-121.90382');
        waypoint7 = new google.maps.LatLng('37.54175', '-121.92334');
        waypoint8 = new google.maps.LatLng('37.51806', '-121.94201');

        // push the waypoints defined above into an array
        wayPointArray = new Array();
    wayPointArray.push({location: waypoint1, stopover: false});
    wayPointArray.push({location: waypoint2, stopover: false});
    wayPointArray.push({location: waypoint3, stopover: false});
    wayPointArray.push({location: waypoint4, stopover: false});
    wayPointArray.push({location: waypoint5, stopover: false});
    wayPointArray.push({location: waypoint6, stopover: false});
    wayPointArray.push({location: waypoint7, stopover: false});
    wayPointArray.push({location: waypoint8 , stopover: false});

    // define our definition position, the last stop of our trip
        destinationPosition = new google.maps.LatLng('37.50162', '-121.93034');

         var request = {
      origin: originPosition,
      destination: destinationPosition,
      waypoints: wayPointArray,
      travelMode: google.maps.DirectionsTravelMode.DRIVING,
      unitSystem: google.maps.DirectionsUnitSystem.METRIC,
      optimizeWaypoints: false
    };

        directionsService.route(request, function(response, status) {

          if (status == google.maps.DirectionsStatus.OK) {



            var polyOpts = {
                strokeOpacity: 1.0,
                strokeColor: '#0000FF',
                strokeWeight: 2
            }

            var directionsDisplayOptions = { 
                suppressMarkers: false, 
                suppressInfoWindows: false, 
                preserveViewport: false,
                polylineOptions: polyOpts
            };

            directionsRenderer = new google.maps.DirectionsRenderer(directionsDisplayOptions);
            directionsRenderer.setMap(map);
            directionsRenderer.setDirections(response);


          } else {

            console.info('could not get route');
            console.info(response);

          }
    });




      }

      google.maps.event.addDomListener(window, 'load', initialize);
    </script> 
  </head> 
  <body> 
    <div id="map_canvas"></div> 
  </body> 
</html> 
4

1 に答える 1

3

これはレンダリングのバグです。

「MergeontoI-680」に続いて地図上に描かれた線は、DirectionsServiceからのJSON応答に表示されるこのエンコードされた文字列によって与えられます。

ylvdFjw|fVMJw@x@[Ha@FUGYOKSEYCYB[F[HOTUXMf@QRGxDoAlBIrBDpBDt@@@?p@?nAArCQlDW`BWjCy@`CwArKyHxGcDpA_@vA[rAWtAOxAKpAEdABhBGpEAvAAfCKnGQzDm@lGkCfGiC~CoAhb@mPrDuA~`@oLn@Q~EgBr@Up@MpAKnBGb@?nBLnAX`AVx@Xt@Z?@z@\\HDfBz@rChAtCj@jDHpCU~Cw@~As@jAw@x@m@bDcCbDeCh@a@fAg@FEf@SBA`Bs@jAM`@Cn@CfB?hBPbB\\`CdA`@NJD^NlAb@bM`GlW~JfHzC|D`CpD~DlAxAl@t@bFvGbApAl@hAVj@Pf@d@rAn@hCjFnUh@|ANd@rCfFxEtIvA|BrNd[zZpr@xAhCfEdFlHxJRVhA`B`@~@t@hBh@`BjAlF`BbIpA~EnA~CpA|B~@lA|A~ArDvCzDzCfClBDB`DtBx@h@fHnDzB|@~B`AjH`DzEnBdAb@jB`@dCRrDJtADnBLpCr@dAd@l@Vz@d@vA`A`@\\d@b@vDlErHzIj@p@LPRRf@n@lB`CjBfCzApCVb@jCdGtClHjCjGjCpGjAxCBFtJbUFNDLx@zBnArC~CtHnCpF`@t@P\\LTP^|@~A\\j@hChElB|CrAxBb@h@t@x@h@j@lA|@~@d@vBt@rCh@lBHxAAdEc@nAa@jAo@~@k@pA}@vFuFvDqDdF}DrFcDlB_AhJeEbEyBVMlAo@rJsEhAm@~EiCtD{AlHeD~GkDxBwAVOZSz@i@TShCwBpJiKfHqI

ノースカロライナ大学のMarkMcClure教授は、http://facstaff.unca.edu/mcmcclur/GoogleMaps/EncodePolyline/decode.htmlにデコーダーを持っており、ラインが表すポイントのリストを作成できます。彼はまた、ポイントのリストを取得し、エンコードされた文字列を生成し、それを地図上に表示するユーティリティを持っています。その文字列をデコードしてから、結果のマップをプロットすると、次のようになります。

グーグルマップの表示

これは偏差を示していません。したがって、Directions Serviceが描画するために提供する線(そのデータによって定義される)は正しいですが、レンダリングは正しくありません。McClureのページがバージョン3ではなくバージョン2のAPIを使用しているため、データを正しくレンダリングできることはおそらく関連性があります。

バグはここで報告する必要があります:http ://code.google.com/p/gmaps-api-issues/issues 。この質問を参照し、レポートで可能な限り詳細を提供することをお勧めします。

于 2012-07-15T08:58:24.140 に答える