私はGoogleマップAPI v3.0を使用しており、DirectionsResultをデータベースに保存してから、後でマップで使用するために取得しています。私の問題は、自分のデータベースからJSON表現を取り除いて保存されたオブジェクトを再水和しようとすると、そのオブジェクトは単にJSONであり、オリジナルのメソッドとその構成オブジェクトの機能がないということです。だから、私はdumbaltテキストJSONを取り、すべてのLatLngとLatLngBoundオブジェクトを再構築することで再構築する修正ルーチンを作成しました。しかし、私の固定オブジェクトは元のように動作しないので、何かがまだ欠けている、2つのポイントは私の地図上に表示されますが、それらの間の紫色の線が欠落しています。GoogleマップのDeserializeできませんDirectionsResultオブジェクト
シリアル化/ハイドレーションのためのより良いテクニック、または私の修正ルーチンが欠落している可能性のあるアイデアに関するアドバイスをいただければ幸いです。
おかげ
request = {
origin: homeLocation,
destination: jobLocation,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
var str = Ext.encode(response); //<<==SAVING RAW JSON OBJECT TO DB (I USE ExtJs)
var z = eval('(' + str + ')'); //<<==REHYDRATING DirectionsResult RAW JSON OBJECT
FixDirectionResult(z); //<<==ATTEMPT TO RE-ESTABLISH ORIGINAL OBJECTS
directionsRenderer.setDirections(z); //<<==THIS WORKS WITH response BUT NOT WITH z
}
);
function FixDirectionResult(rslt) {
for(r=0; r<rslt.routes.length; r++) {
var route = rslt.routes[r];
var bounds = route.bounds;
route.bounds = new google.maps.LatLngBounds(
new google.maps.LatLng(bounds.U.b,bounds.O.d),
new google.maps.LatLng(bounds.U.d,bounds.O.b));
for(l=0; l<route.legs.length;l++) {
var leg = route.legs[l];
leg.start_location = new google.maps.LatLng(leg.start_location.wa,leg.start_location.ya);
leg.end_location = new google.maps.LatLng(leg.end_location.wa,leg.end_location.ya);
for(s=0; s<leg.steps.length;s++) {
var step = leg.steps[s];
step.start_location =
new google.maps.LatLng(step.start_location.wa,step.start_location.ya);
step.end_location =
new google.maps.LatLng(step.end_location.wa,step.end_location.ya);
for(p=0;p<step.path.length;p++) {
var path=step.path[p];
step.path[p] = new google.maps.LatLng(step.path.wa,step.path.ya);
}
}
}
for(o=0; o<route.overview_path.length;o++) {
var overview = route.overview_path[o];
route.overview_path[o] = new google.maps.LatLng(overview.wa,overview.ya);
}
}
}
誰もが興味を持っていた場合、私もGoogleマップのフォーラムにこのクエリをも掲載しました:https://groups.google.com/d/topic/google-maps-js-api-v3/Ai1bZIVgfzo /討論 – sisdog