Posted: Wed Sep 06, 2006 5:02 pm
I am sorry to say but currently I don't have Google API code/key so I am unable to help you further on this...
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
var query = parseQueryString();
var map,geocoder,centre,marker;
var mapData = {
def: {
addr: '76 Main St East, Grimsby, On',
caption: 'The Main Office For eCompulab, located Just <br/>off the highway in scenic grimsby, ontario'
},
one: {
addr: '181 South Service Rd., Grimsby, On',
caption: 'Our Secondary Office, Located Just off the highway<br/> in scenic grimsby, ontario'
},
two: {
addr: '21 Main St. E. Grimsby, On',
caption: 'Our Retail Store, Located in the Downdown city<br/> centre in scenic grimsby, ontario',
lat: 43.192542,
lng: -79.559653
}
};
function load() {
curLoc = (mapData[query.loc])?mapData[query.loc]:mapData.def;
if (GBrowserIsCompatible() && curLoc) {
document.title += ' '+curLoc.addr;
if (!curLoc.lat || !curLoc.lng) {
geocoder = new GClientGeocoder();
geocoder.getLocations(curLoc.addr, function(response){
if (!response || response.Status.code != 200) {
alert("Sorry, we were unable to geocode that address");
} else {
place = response.Placemark[0];
centre = new GLatLng(place.Point.coordinates[1], place.Point.coordinates[0]);
marker = new GMarker(centre);
loadMap(centre,marker,{addr:place.address,caption:curLoc.caption});
}
});
} else {
centre = new GLatLng(curLoc.lat, curLoc.lng);
marker = new GMarker(centre);
loadMap(centre,marker,{addr:curLoc.addr,caption:curLoc.caption});
}
}
}
function loadMap(centre,marker,place) {
map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(centre, 15);
map.addOverlay(marker);
html = '<strong>'+place.addr+'</strong>';
if (place.caption) html += '<br/>'+place.caption;
marker.openInfoWindowHtml(html);
}try to 'rename' this variable like:The Ninja Space Goat wrote:Still not working...
I think that the fact that it is being used as a callback function is messing up its state or something...
Code: Select all
function objectConstructor() {
var me = this; // <======== magic :))
this.data = [];
this.callbackFunction = function(arg) {
me.data.push(arg);
}
}
Code: Select all
function UCA(){
// TODO: Find a better way to encapsulate this stuff
var street = $F('street');
var city = $F('city');
var state = $F('state');
var zip = $F('zip');
var address = street + ", " + city + ", " + state + ", " + zip;
this.locations;
this.geocoder = new GClientGeocoder;
this.geocoder.getLocations(address, this.handleResponse);
this.handleResponse = function(response){
var me = this;
if(response.Status.code == 200){
me.locations = response.Placemark;
}
}
alert(this.locations); // alerts "undefined"
}
Code: Select all
<input type="button" value="Locate" onclick="var loc = new UCA(); alert(loc.locations);" />Code: Select all
function UCA(){
// TODO: Find a better way to encapsulate this stuff
var street = $F('street');
var city = $F('city');
var state = $F('state');
var zip = $F('zip');
var address = street + ", " + city + ", " + state + ", " + zip;
this.locations;
this.geocoder = new GClientGeocoder;
this.geocoder.getLocations(address, this.handleResponse); // This calls the handle response function
this.handleResponse = function(response){
var me = this; // rename this
if(response.Status.code == 200){ // I know this is true, I tested it
me.locations = response.Placemark; // and if I alert(me.locations) I get the expected result
}
}
alert(this.locations); // but now down here it's undefined again
}
you're supposed to move that line to constructorvar me = this; // rename this
Code: Select all
// TODO: Find a better way to encapsulate this stuff