Hi,
Can anyone help me with the fact that the following code works in FF, but in IE, it generates the error
‘lastChild.children’ is null or not an object
if (GBrowserIsCompatible()) {
var numbers = [];
var types = [];
var prices = [];
var polys = [];
// Display the map, with some controls and set the initial location
var map = new GMap2(document.getElementById("map"), { mapTypes:[G_HYBRID_MAP] });
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(<?php echo $centerlat . ", " . $centerlng ?>),17);
GEvent.addListener(map, "click", function(overlay,point) {
var T1 = new Date();
if (!overlay) {
for (var i=0; i<polys.length; i++) {
if (polys[i].Contains(point))
{
var area = polys[i].Area()/* /1000000*/;
var sqmiles = area/2.58998811;
var T2 = new Date();
map.openInfoWindowHtml(point,"This is plot <b>"+numbers[i] + "</b><br>"
+ "Housetype: <b>" + types[i] + "</b><br>"
+ "Price is: <b>" + prices[i] + "</b><br>"
+"The area of "+numbers[i]+" is "+parseInt(area)+ "sq m" + "<br>"
// +".<br>that's "+parseInt(sqmiles)+" square miles<br>"
// +"Its boundary is "+parseInt(polys[i].Distance()/1609.344)+" miles long"
+"<hr>Time taken = "+(T2.getTime()-T1.getTime())+" milliseconds"
); i = 999; // Jump out of loop
}
}
}
});
// Read the data from plots.xml
var request = GXmlHttp.create();
request.open("GET", "write.xml", true);
request.onreadystatechange = function() {
if (request.readyState == 4) {
var xmlDoc = GXml.parse(request.responseText);
// ========= Now process the polylines ===========
var plots = xmlDoc.documentElement.getElementsByTagName("plot");
// read each line
for (var a = 0; a < plots.length; a++) {
// get any state attributes
//var label = plots[a].getAttribute("name");
// ISSUE STARTS HERE!!!
var number = xmlDoc.lastChild.children[a].children[1].firstChild.nodeValue;
var type = xmlDoc.lastChild.children[a].children[3].firstChild.nodeValue;
var price = xmlDoc.lastChild.children[a].children[4].firstChild.nodeValue;
// ISSUE ENDS HERE!!!
var colour = "#ff0000";
//var colour = plots[a].getAttribute("colour");
// read each point on that line
var points = plots[a].getElementsByTagName("point");
var pts = [];
for (var i = 0; i < points.length; i++) {
pts[i] = new GLatLng(parseFloat(points[i].getAttribute("lat")),
parseFloat(points[i].getAttribute("lng")));
}
var opaque =0.25;
var strokeopacity = 1;
var strokewidth = 1;
var poly = new GPolygon(pts,"#000000",strokewidth,strokeopacity,colour,opaque,{clickable:false});
polys.push(poly);
numbers.push(number);
types.push(type);
prices.push(price);
map.addOverlay(poly);
}
// ================================================
}
}
request.send(null);
}
// display a warning if the browser was not compatible
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
Thanks