Solved

Javascript Error with using Google map in IE

Posted on 2006-11-05
10
1,072 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
ID: 17876932
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
ID: 17877312
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17877645
>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
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17877653
>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
ID: 17878856
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
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17879713
This is really strange!
0
 
LVL 3

Author Comment

by:Abdu_Allah
ID: 17879743
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
ID: 17880105
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
ID: 17881275
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
ID: 17886893
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
jqury 17 30
JavaScript let vs var 5 26
How to deal with the query string 7 18
Add shadow behind div 5 8
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

773 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