2011-07-11 12 views
2

このGoogleマップのルートパスに座標を取得するにはどうすればよいですか?

http://maps.google.com/maps?f=d&hl=en&saddr=25.04202,121.534761 
&daddr=25.05202,121.554761&ie=UTF8&0&om=0&output=kml 

ようなリンクを使用している場合、それは以下のように座標の値を返す:

121.534760,25.042040,0.000000 121.533650,25.042190,0.000000 121.532950,25.042430,0.000000 121.532950,25.042430 、0.000000 121.532980,25.044400,0.000000 121.532980,25.044400,0.000000 121.534000,25.044670,0.000000 121.534400,25.044820,0.000000 121.535690,25.045690,0.000000 121.536400,25.045990,0.000000 121.540510,25.046700,0.000000 121.543860,25.047490,0.000000 121.546430,25.048160,0.000000 121.549130,25.048140 、0.000000 121.549130,25.048140 、0.000000 121.550770,25.048110,0.000000 121.552570,25.048140,0.000000 121.552570,25.048140,0.000000 121.552700,25.049850,0.000000 121.552750,25.051440,0.000000 121.552650,25.051540,0.000000 121.552640,25.051680,0.000000 121.552640,25.051680,0.000000 121.552660,25.052280,0.000000 121.552660,25.052280 、0.000000 121.553770,25.052260,0.000000 121.553770,25.052260,0.000000 121.554770,25.052240,0.000000

が、私のjavascriptので、それは5-6で

を調整し、およそわずか数座標を返してここに得るために私のコードです座標:

function route(FromPlace,ToPlace){ 
if(!FromPlace&&!ToPlace){ 
    FromPlace = new google.maps.LatLng(13.692941, 100.750723); 
    ToPlace = document.getElementById("endPoint").value; 
} 
    //directionsService = new google.maps.DirectionsService(); 
    var request = { 
      origin: FromPlace, 
      destination: ToPlace, 
      travelMode: google.maps.DirectionsTravelMode.DRIVING 
     }; 
    directionsService.route(request, function(response, status) { 
     if (status == google.maps.DirectionsStatus.OK) 
     { 

      directionsDisplay.setDirections(response); 
    for (var i = 0; i < response.routes[0].legs.length; i++) { 
      for (var j = 0; j < response.routes[0].legs[i].steps.length; j++) { 
       if(j == response.routes[0].legs[i].steps.length-1){ 

        addressRoute = addressRoute+response.routes[0].legs[i].steps[j].end_point.lat()+"," 
         +response.routes[0].legs[i].steps[j].end_point.lng()+""; 
        latitude = response.routes[0].legs[i].steps[j].end_point.lat(); 
        longitude = response.routes[0].legs[i].steps[j].end_point.lng(); 
        destinationDB = latitude +","+ longitude; 
        }else{ 

        addressRoute = addressRoute+response.routes[0].legs[i].steps[j].end_point.lat()+"," 
         +response.routes[0].legs[i].steps[j].end_point.lng()+"|"; 

        } 
       } 
      } 
      //document.getElementById("textLocation").innerHTML = addressRoute; 
     } 
     }); 
    } 

上記のリンクのようにより具体的な座標を取得するためにコードを改善するにはどうすればよいですか? はありますか? :)

+0

あなたはより高い精度を求めていますか?つまり度:分:秒です。 – thegrinner

答えて

2

steps [j] .start_pointとsteps [j] .end_pointではなく、各ステップオブジェクトに含まれるパスオブジェクトです。あなたがいないだけで、開始点と終了点、同様にあなたのステップパスの全てでそれぞれ、すべてのポイントを取得したい

route.legs.forEach(function(leg){ 
    leg.steps.forEach(function(step){ 
     step.path.forEach(function(point){ 
      debug_panel.innerHTML+=point+"<br/>"; 
     }); 
    }); 
}); 

:それは言うことです。

希望するもの

関連する問題