私のアプリケーションでは、マップ上の2つのポイントを選択し、それらの間のルートをGoogle maps Apiv3のDirections Serviceを使用して見つけることができます。次に、このルートに沿った座標をデータベースに保存する必要があります。私はこれを達成するためにすべてのコードを書くことに成功しました。しかし、私は問題が残されていません。GoogleマップのDirections Serviceで生成されたルートに沿ったすべての座標を取得するApiv3
私は、StackOverflowにOne、Twoという複数の質問があることを知っていますが、確かに彼らか私がここで何かを逃していると思います。
サンプルコード:
function getCoordinates(result) {
var currentRouteArray = result.routes[0]; //Returns a complex object containing the results of the current route
var currentRoute = currentRouteArray.overview_path; //Returns a simplified version of all the coordinates on the path
obj_newPolyline = new google.maps.Polyline({ map: map }); //a polyline just to verify my code is fetching the coordinates
var path = obj_newPolyline.getPath();
for (var x = 0; x < currentRoute.length; x++) {
var pos = new google.maps.LatLng(currentRoute[x].kb, currentRoute[x].lb)
latArray[x] = currentRoute[x].kb; //Returns the latitude
lngArray[x] = currentRoute[x].lb; //Returns the longitude
path.push(pos);
}
}
上記のコードは緯度とLNGの座標を保持するように見える概要パスのkb
とlb
プロパティは常に同じではないことを除いて完璧に動作します。コードを最後に作成したときは、kb
とlb
が数日続き、その後mb
,nb
、今日はjb
とkb
に変更されました。
私は上記以外のlatlngを提供できるオブジェクトの他のプロパティは表示されません。他の同様の質問への回答には、この問題が言及されています。私はここに何かを逃していますか信頼できる解決策をお願いします。
あなたは私のヒーローです – zz3599
うわー!ありがとうございました! – Jonathan