I have a class object called Location that works with Google in order to geocode a given address. The geocode request is made trough an AJAX call and handled via a callback that will initiate the class members once the response arrives.
Here is the code:
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] }
My question is: it's possible to wait the response from Google before exiting the constructor?
I have no control over the AJAX request since it's made trough Google APIs.
I want to be sure that this.coord[]
is properly initialized once a Location obj is created.
Thank you!