Solved

Javascript Error with using Google map in IE

Posted on 2006-11-05
10
1,077 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
href return to normal window 5 29
JS library vs Js framework 11 23
Popup write two lines 3 22
What is the correct way to check for empty value in input field 2 17
Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
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…

749 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