私たちは、GoogleマップAPIを使用して、私たちのエリアの小型船会社の物流と計画を支援するASP.NETアプリケーションを開発しています。機能の1つは、会社が顧客のリストを入力することであり、システムは一連のウェイポイントとしてすべての顧客アドレスをパッケージ化し、Googleに送信し、ルートの方向情報を取得します。Google Maps API - エラーの原因となったウェイポイントの発見
私たちが抱えていた1つの問題は、データベース内の多くのアドレスが大きくなく、しばしばGoogleマップで処理できないことです。これを行うと、エラーコードが返ってきますが、どのウェイポイントが失敗するのかを判断できるようになります(クライアントがデータベースのアドレスを修正することができます)。ここ
EDITは、初期化し、現在のエラー処理を処理するコードのチャンクである:
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GSmallMapControl());
gdir = new GDirections(map);
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
if (document.getElementById("<%=hiddenWayPoints.ClientID %>").getAttribute("value") != '')
{
setDirections();
}
}
}
function setDirections() {
var waypoints = new Array();
var str = document.getElementById("<%=hiddenWayPoints.ClientID%>").getAttribute("value");
waypoints = document.getElementById("<%=hiddenWayPoints.ClientID %>").getAttribute("value").split(":");
gdir.loadFromWaypoints(waypoints, {getSteps:true});
}
function handleErrors(){
if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
alert("No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
alert("The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_KEY)
alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code);
else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
alert("A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code);
else alert("An unknown error occurred.");
}
問題がGDirectionsオブジェクト内LoadFromWayPoints()メソッドはステータスを返すようには見えないということですそれぞれの個々のウェイポイントに基づいていますが、リスト全体からのみです(すべてが失敗した場合はすべて失敗します)。
私が考えることができる唯一の実際の解決策(システムの他の領域でチェックを行わない)は、別のリクエストでGoogleマップに各ウェイポイントを送信し、そのウェイポイントリスト全体を送信する前に有効性をチェックすることですGDirectionsオブジェクトの場合は非常に非効率的です(特に、より多くの顧客の場所を扱う場合)。
あなたの編集(私は今見ている、申し訳ありません)は、私の特定の問題に関するより良い情報を提供しました。あなたが持ってきた2つのポイントは、まさに私の頭の中を走っていたものでした(私はそれを分割し、最初に入場または選択されたときに個々の住所をチェックすると余分な往復について)。私が決めたのは、自分が望む個々のアドレスだけをチェックする確認ボタンを追加することです。これは、私が信じている多くの不必要なチェックを節約します。 – TheTXI