In the below code.
Please see the portion marked with 'red' color.
The property for both 'marker' and 'map' is getting there.
But inside the GEvent.addListener() the its not happening (alert showing
'undefined'.)
Why the property of both 'map' and 'marker' is not getting inside?
Any idea?
GMap = function(id, address, label)
{
this.id = id;
this.address = address;
this.label = typeof label == "undefined" ? address : label;
this.geocoder = new GClientGeocoder();
}
GMap.prototype = {
id:'',
map:'',
geocoder:'',
address:'',
marker:'',
label:'',
show:function()
{
if (this.address.indexOf(" ") !== -1)
{
this.address.replace(/\s/, "+");
}
this.geocoder.getLatLng(
this.address,
function(point)
{
if (!point)
{
m.showDefaultMap();
}
else
{
m.showMap(point);
}
}
);
},
setAddress:function(address)
{
if (typeof address == "object")
{
var a = address;
this.address = a["address"]+", "+
a["city"]+
(typeof a["state"] == "undefined" ? "": ", "+a["state"])+
(typeof a["country"] == "undefined" ? "" : ", "+a["country"])+
(typeof a["zip"] == "undefined" ? "" : ", "+a["zip"]);
}
else
{
this.address = address;
}
},
setLabel:function(l)
{
this.label = l;
},
showDefaultMap:function()
{
if (typeof this.map != 'object')
{
this.map = new GMap2(document.getElementById(this.id));
this.map.addControl(new GHierarchicalMapTypeControl());
this.map.addControl(new GOverviewMapControl());
this.map.addControl(new GLargeMapControl3D());
}
this.map.setCenter(new GLatLng(GMAP_DEF_LAT,GMAP_DEF_LNG), GMAP_DEF_ZOOM);
},
showMap:function(point)
{
var imageUrl="../../../images/web_map_pointer.png";
var hIcon = new GIcon();
hIcon.image = imageUrl;
hIcon.iconSize = new GSize(42,58);
hIcon.iconAnchor = new GPoint(25,25);
if (typeof this.map != 'object')
{
this.map = new GMap2(document.getElementById(this.id));
this.map.addControl(new GHierarchicalMapTypeControl());
this.map.addControl(new GOverviewMapControl());
this.map.addControl(new GLargeMapControl3D());
}
this.map.setCenter(point, 13);
if (typeof this.marker != "object")
{
this.marker = new GMarker(point,hIcon);
this.map.addOverlay(this.marker);
//this.marker.openInfoWindowHtml(this.label||this.address);
this.map.openInfoWindowHtml(point,this.label||this.address);
alert(this.marker);
alert(this.map);
GEvent.addListener(this.marker,'click',
function() {
alert(this.marker);
alert(this.map);
this.map.openInfoWindowHtml(point,this.label||this.address);
}
);
}
else
{
this.marker.setLatLng(point);
this.marker.openInfoWindowHtml(this.label||this.address);
}
}
};
--
You received this message because you are subscribed to the Google Groups
"Google Maps API V2" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-maps-api?hl=en.