Skip to content

Instantly share code, notes, and snippets.

@tf0054
Created June 5, 2010 04:19
Show Gist options
  • Save tf0054/426300 to your computer and use it in GitHub Desktop.
Save tf0054/426300 to your computer and use it in GitHub Desktop.
// googleサービス
directionsService.route(request, function(response, status) {
// 正しく経路が得られているか確認
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setMap(null);
directionsDisplay.setMap(map);
directionsDisplay.setDirections(response);
// 距離をステップ合計から計算(ほんとうにこんな方法がよいのか。。)
var intTmp = 0;
for(var i in response.routes[0].legs[0].steps){
intTmp += response.routes[0].legs[0].steps[i].distance.value;
}
// 距離が1000mを超えたら単位を変更
if(intTmp > 1000){
document.getElementById('distance').innerHTML = '('+(intTmp/1000)+'km)';
}else{
document.getElementById('distance').innerHTML = '('+intTmp+'m)';
}
// 経路上の距離を表示してみる From http://bit.ly/cKh1mU
// document.getElementById('map_canvas').innerHtml = response.trips[0].routes[0].distance.value;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment