I am having trouble with the following code:
function initialize() {
//myLatLng = new google.maps.LatLng(37.422104808,-122.0838851);
var myOptions = {
zoom: 18,
center: new google.maps.LatLng(42.564613,-70.809087),
// zoom: 5,
// center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
geoXml = new geoXML3.parser({
map: map,
singleInfoWindow: true,
afterParse: useTheData
});
geoXml.parse('ActivityStatus_Producing_labels.kml');
};
function kmlClick(marker) {
google.maps.event.trigger(geoXml.docs[0].markers[marker],"click");
}
function useTheData(doc){
// Geodata handling goes here, using JSON properties of the doc object
var sidebarHtml = "<table>";
for (var i = 0; i < doc[0].markers.length; i++) {
// console.log(doc[0].markers[i].title);
sidebarHtml += '<tr><td><a href="javascript:kmlClick('+i+');">'+doc[0].placemarks[i].name+'</a></td></tr>';
}
I am getting an error that doc[0].markers.length cannot get the length from a null or non existent variable depending on which browser I use.
In this website: http://thoughtfi.com/geoxmlpractice/practiceIMR2.html I can get it to run in Chrome but not IE
This website works in IE and Chrome and has almost the same code: http://www.geocodezip.com/geoxml3_test/v3_geoxml3_us_states_kml_test.html
How can I get my site to work? I’m guessing it’s not parsing the kml file in time or the server/browser is too slow to parse the kml?
It seems to be the kml file. IE doesn’t believe it is valid xml. Neither does feedvalidator:
http://www.feedvalidator.org/check.cgi?url=http%3A%2F%2Fthoughtfi.com%2Fgeoxmlpractice%2FActivityStatus_Producing_labels.kml#l675
If I fix the invalid xml (and the character encoding the xml file reports), it works for me:
http://www.geocodezip.com/geoxml3_test/thoughtfi_com_geoxmlpractice_practiceIMR2a.html
Here is another example displaying the “fixed” kml
You can also see what Google Maps thinks of your kml: