Solved

Javascript Error with using Google map in IE

Posted on 2006-11-05
10
1,064 Views
Last Modified: 2008-01-09
Hi, I am using Google documentation example http://www.google.com/apis/maps/documentation/#Using_XML_and_Asynchronous_RPC
 Bu I got javascript error and it does not show all the markers in IE but that code works fine in firefox.

Here is my entire page:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html >
  <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title>Google Maps JavaScript API Example</title>
    <script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAt1tJUSGuvrApoZU9F246RRS2oTgyHBeaRCId_8WE_PRPpcBecRRhMqgKTHwwPYrzpZtPqzLXYsqDyA"
            type="text/javascript"></script>
    <script type="text/javascript">
    //<![CDATA[

    function load() {
      if (GBrowserIsCompatible()) {
        var map = new GMap2(document.getElementById("map"));
        map.addControl(new GSmallMapControl());
        map.addControl(new GMapTypeControl());
        map.setCenter(new GLatLng(23.4419, 15.1419), 2);

        // Download the data in data.xml and load it on the map. The format we
        // expect is:
        // <markers>
        //   <marker lat="37.441" lng="-122.141"/>
        //   <marker lat="37.322" lng="-121.213"/>
        // </markers>
        GDownloadUrl("data.xml", function(data, responseCode) {
          var xml = GXml.parse(data);
          var markers = xml.documentElement.getElementsByTagName("marker");
         for (var i = 0; i < markers.length; i++) {
            var point = new GLatLng(parseFloat(markers[i].getAttribute("lat")),
                                    parseFloat(markers[i].getAttribute("lng")));
            map.addOverlay(new GMarker(point));
          }
        });
      }
//      clearOverlays();
    }

    //]]>
    </script>
  </head>
  <body onload="load()" onunload="GUnload()">
    <div id="map" style="width: 790px; height: 300px"></div>
  </body>
</html>
0
Comment
Question by:Abdu_Allah
10 Comments
 
LVL 16

Assisted Solution

by:Peter Kwan
Peter Kwan earned 200 total points
Comment Utility
What javascript error do you get? Is your data.xml present in the same directory as the HTML resides?

I have tried your code in IE6 and found no error if the data.xml is present.
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 50 total points
Comment Utility
0
 
LVL 3

Author Comment

by:Abdu_Allah
Comment Utility
>What javascript error do you get?

Line: 7
Char: 67
Error: Invalid Argument
Code: 0

>Is your data.xml present in the same directory as the HTML resides?

Yes
0
 
LVL 3

Author Comment

by:Abdu_Allah
Comment Utility
>I have tried your code in IE6 and found no error if the data.xml is present.

Did it show the entire markers?
0
 
LVL 5

Expert Comment

by:ewilde
Comment Utility
i tried it too in ie6 & ie7 and in worked for me. the markers showed up as expected.
maybe you have some problem with your data.xml file?

i used this:

 <markers>
   <marker lat="37.441" lng="-122.141"/>
   <marker lat="37.322" lng="-121.213"/>
   <marker lat="37.122" lng="-121.213"/>
 </markers>


good luck,
ewilde.
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 3

Author Comment

by:Abdu_Allah
Comment Utility
This is really strange!
0
 
LVL 3

Author Comment

by:Abdu_Allah
Comment Utility
ewilde how your entire xml file look like, could you please copy&paste the entire file.
0
 
LVL 5

Assisted Solution

by:ewilde
ewilde earned 250 total points
Comment Utility
this is the whole of it:


 <markers>
   <marker lat="37.441" lng="-122.141"/>
   <marker lat="37.322" lng="-121.213"/>
   <marker lat="37.122" lng="-121.213"/>
 </markers>
0
 
LVL 3

Author Comment

by:Abdu_Allah
Comment Utility
Well, it seems the problem has disappeared by itself!! I did not do any changes!

However, ewilde  or anyone else, please try to add another <marker> nodes with different values, these new marker will not appear on the map! Is it a chashing problem? if so how to resolve it?
Thanks.
0
 
LVL 5

Assisted Solution

by:ewilde
ewilde earned 250 total points
Comment Utility
in order to force the browser to reload the data.xml you need to change the url every time you load it.  so do the folowing:

1. add this function to your script:

function createTimestamp(){
  return "timestamp=" + new Date().getTime().toString();
};

2. and use it when you load the data.xml file:

        GDownloadUrl("data.xml?"+createTimestamp(), function(data, responseCode) {


good luck,
ewilde.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now