Advertisement

09.18.2008 at 03:33PM PDT, ID: 23744270
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

Using two XML files at once in Google Maps API

Asked by RobPal in Asynchronous Javascript and XML (AJAX), JavaScript, Active Server Pages (ASP)

Tags: ,

Hi there experts!

I am developing a site using Google Maps API and I am trying to dynamically create markers with info windows filled with information stored in an XML file which was also dynamically created during the page load process.

I think my problem may stem from trying to have two XML files being read simultaneously.

The basic code to place a marker using lat and lng from an XML file works perfectly and also populating an info window for each marker using randomly generated numbers in javascript.  The problem occurs when I try and generate html for the infowindow by reading value from another XML file.  The first XML file is still being read at the same time as it's looping through each marker to get the lat and lng values then as it's placing the marker and before it moves onto the next one it goes to the next XML file to pull through the values for the infowindow html.

I get the following error when a marker is clicked on the map:-

documentElement is null or not an object

The code is below(starting with the display_sales function but problem occurring within the createHTML function), any help you can give would be most appreciated.

I've also attached my xml files but in txt format as it won't let me upload xml files.

Cheers,

RobStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
<script type="text/javascript">
 var geocoder = new GClientGeocoder(); 
 var map = null;
 
    function initialize() {
          if (GBrowserIsCompatible()) {
          			map = new GMap2(document.getElementById("map_canvas"));                 
                          map.setCenter(new GLatLng(54.3165, -3.2520), 5);
                          map.addControl(new GSmallMapControl());
                          map.addControl(new GMapTypeControl());
                                }    } 
                
    function showAddress(address) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
              map.setCenter(point, 13);
              //var marker = new GMarker(point);
              //map.addOverlay(marker);
            	   }
            			  }
        				  );
    				}
    				}
    
    function createHTML(s_code) {
    var scode = "\"" + s_code + "\"";
    GDownloadUrl("images/data/infwin.xml", function(data, responseCode) {
    var xml2 = GXml.parse(data);
    var infwins = xml2.documentElement.getElementsByTagName(scode);
    var o_name = parseFloat(infwins[0].getAttribute("name"));
    var o_add1 = parseFloat(infwins[0].getAttribute("add1"));
    myhtml2 = "<font face=Arial size=2><b>Sale Code: " + scode + "</b></font><br>";
    //myhtml2 = myhtml2 + "<font face=Arial size=2><b>Outlet Name: " + o_name + "</b></font><br>";
    //html = html + "<font style=Arial size=2 color=red><p>" + o_add1 + "</p></font><br>";
	}
	);
    return myhtml2;
    }
    
    
	function createMarker(point,myhtml) {
  	var marker = new GMarker(point);
  	GEvent.addListener(marker, "click", function() {
    marker.openInfoWindowHtml(createHTML(myhtml));
  	});
  	return marker;
	}
			
    function display_sales() {
    GDownloadUrl("images/data/mkrs.xml", function(data, responseCode) {
    var xml = GXml.parse(data);
    var markers = xml.documentElement.getElementsByTagName("marker");
    var outlets = xml.documentElement.getElementsByTagName("outlet");
    for (var i = 0; i < markers.length; i++) {
    var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
    parseFloat(markers[i].getAttribute("lng")));
    var html = outlets[i].getAttribute("s_code");
    map.addOverlay(createMarker(point, html));
    }});
 
}			 
</script>
Attachments:
 
The file for the info windows data (the second one to be accessed)
 
 
The primary markers data (the first one to be accessed and the one that works fine)
 
[+][-]09.20.2008 at 10:39AM PDT, ID: 22530768

Experts Exchange has a courteous staff of administrators who help members get the most out of the website by means of administrative comments like this one.

Start your 7-day free trial to view this Administrative Comment or ask the Experts your question.

 
[+][-]09.20.2008 at 11:37AM PDT, ID: 22531029

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]09.20.2008 at 03:41PM PDT, ID: 22531990

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Asynchronous Javascript and XML (AJAX), JavaScript, Active Server Pages (ASP)
Tags: ASP, Javascript, documentElement is null or not an object
Sign Up Now!
Solution Provided By: RobPal
Participating Experts: 1
Solution Grade: A
 
 
[+][-]09.22.2008 at 03:48AM PDT, ID: 22538802

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628