特定の住所をジオコーディングするためにGoogleと連携するLocationというクラスオブジェクトがあります。ジオコード要求はAJAX呼び出しを介して行われ、応答が到着するとクラスメンバーを開始するコールバックを介して処理されます。
コードは次のとおりです。
function Location(address) {
this.geo = new GClientGeocoder();
this.address = address;
this.coord = [];
var geoCallback = function(result) {
this.coord[0] = result.Placemark[0].Point.coordinates[1];
this.coord[1] = result.Placemark[0].Point.coordinates[0];
window.alert("I am in geoCallback() lat: " + this.coord[0] + "; lon: " + this.coord[1]);
}
this.geo.getLocations(this.address, bind(this, geoCallback));
}
Location.prototype.getAddress = function() { return this.address; }
Location.prototype.getLat = function() { return this.coord[0] }
Location.prototype.getLng = function() { return this.coord[1] }
私の質問は、コンストラクターを終了する前にGoogleからの応答を待つことは可能ですか?
AJAXリクエストはGoogleAPIを介して作成されているため、制御できません。
this.coord[]
Location objが作成されたら、それが正しく初期化されていることを確認したいと思います。
ありがとうございました!