473,231 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,231 software developers and data experts.

Javascript & Google Maps error.

I'm fairly new to Javascript and it's more of a guessing game for me...
I'm trying to build an app for Google Maps and just had some issues recently.
First off I just wanted to say that everything works fine in FF and IE. It's Chrome I'm having issues with.
I understand that Chrome is still somewhat in beta stages, so some bugs might occur. However this seems like something I might have done.
So...
I used a code that I found on Econym as a base and modified it slightly. Here is what I have:
Expand|Select|Wrap|Line Numbers
  1. <div>
  2.         <div id="search" align="center">
  3.             <table border="1">
  4.                 <tr>
  5.                     <td>
  6.                         <div id="map" style="width: 690px; height: 450px">
  7.                         </div>
  8.                     </td>
  9.                     <td width="250" valign="top" style="color: #4444ff;">
  10.                         <!-- =========== side_bar with scroll bar ================= -->
  11.                         <div id="side_bar" style="overflow: auto; height: 450px;">
  12.                         </div>
  13.                         <!-- ===================================================== -->
  14.                     </td>
  15.                 </tr>
  16.             </table>
  17.             <noscript>
  18.                 <b>JavaScript must be enabled in order for you to use Google Maps.</b> However,
  19.                 it seems JavaScript is either disabled or not supported by your browser. To view
  20.                 Google Maps, enable JavaScript by changing your browser options, and then try again.
  21.             </noscript>
  22.  
  23.             <script type="text/javascript">
  24.                 //<![CDATA[
  25.                 if (GBrowserIsCompatible()) 
  26.                 {
  27.                     var side_bar_html = "";
  28.                     var gmarkers = [];
  29.                     var htmls = [];
  30.                     var i = 0;
  31.  
  32.                     // A function to create the marker and set up the event window
  33.  
  34.                     function createMarker(point,name,html,address,phone) 
  35.                     {
  36.                         var marker = new GMarker(point);
  37.                         GEvent.addListener(marker, "click", function() 
  38.                             {
  39.                                 marker.openInfoWindowHtml(html);
  40.                             }
  41.                         );
  42.                         gmarkers[i] = marker;
  43.                         htmls[i] = html;
  44.  
  45.                         side_bar_html += '<p id="location"><a href="javascript:myclick(' + i + ')">' + name + '<\/a><br><em><strong>Address: </strong>' + address + '<br><strong>Phone: </strong>' + phone + '</em></p>';
  46.                         i++;
  47.                         return marker;
  48.                     }
  49.  
  50.                     //Function to proccess the click on the navigation slider
  51.  
  52.                     function myclick(i) 
  53.                     {
  54.                         gmarkers[i].openInfoWindowHtml(htmls[i]);
  55.                     }
  56.  
  57.                     // create the map
  58.  
  59.                     var map = new GMap2(document.getElementById("map"));
  60.                     map.addControl(new GLargeMapControl());
  61.                     map.addControl(new GMapTypeControl());
  62.                     map.setCenter(new GLatLng(40.000000,-79.359741), 13);
  63.  
  64.                     GDownloadUrl("http://localhost:64109/WebSite28/XMLportland.xml", function(doc) {
  65.                     var xmlDoc = GXml.parse(doc);
  66.                     var markers = xmlDoc.documentElement.getElementsByTagName("marker");
  67.                     for (var i = 0; i < markers.length; i++) 
  68.                     {
  69.  
  70.                         // obtain the attribues of each marker
  71.  
  72.                         var lat = parseFloat(markers[i].getAttribute("lat"));
  73.                         var lng = parseFloat(markers[i].getAttribute("lng"));
  74.                         var point = new GLatLng(lat,lng);
  75.                         var html = markers[i].getAttribute("html");
  76.                         var label = markers[i].getAttriEconym bute("label");
  77.                         var address = markers[i].getAttribute("address");
  78.                         var phone = markers[i].getAttribute("phone");
  79.                         var marker = createMarker(point,label,html,address,phone);
  80.                         map.addOverlay(marker);
  81.                     }
  82.  
  83.                     document.getElementById("side_bar").innerHTML = side_bar_html;
  84.                 });
  85.             }
  86.         else {
  87.             alert("Sorry, the Google Maps API is not compatible with this browser");
  88. }
  89.             </script>
  90.  
  91.         </div>
  92.     </div>
  93.  
And my XML file looks like this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="utf-8" standalone="no"?>
  2. <markers>
  3.   <marker lat="43.6281251" lng="-70.2947086" html="&lt;div id='desc'&gt;&lt;h3&gt;Facility Name&lt;/h3&gt;&lt;p&gt;&lt;span&gt;Address: &lt;/span&gt;380 Main Street&lt;br /&gt;South Portland, ME, 04106&lt;br /&gt;&lt;span&gt;Phone: &lt;/span&gt;(555) 555-5555&lt;br&gt;&lt;span&gt;Hours: &lt;/span&gt;Monday - Friday: 7:30AM-5PM&lt;br /&gt;&lt;span&gt;Saturday: &lt;/span&gt;8AM-12PM&lt;br /&gt;&lt;span&gt;Sunday: &lt;/span&gt;Closed&lt;/p&gt;&lt;img src='images/AARLogo.jpg' alt='Approved Auto Repair' width='100px' height='66px' align='right' id='Logo' /&gt;&lt;h4&gt;Available Services&lt;/h4&gt;&lt;div id='col1'&gt;&lt;table class='services'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Engine Tune Up&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Minor Engine Repair&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Brakes&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Electrical Systems&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Tires, Steering, Suspension&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Heating/Cooling &amp; AC&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Major Engine repair&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;div id='col2'&gt;&lt;table class='services'&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Automatic Transmission&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Manual Transmission&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Diagnostic Services&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Smog Check&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Brake Certification&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Lamp Certification&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;&lt;td&gt;&lt;img src='images/check_empty.jpg' width='13px' height='13px' alt='Yes' /&gt;&lt;/td&gt;&lt;td&gt;Automotive Diesel Repairs&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;&lt;/div&gt;&lt;/div&gt;" label="Facility Name" address="380 Main Street&lt;br /&gt;Boston, MA" phone="(555) 555-5555" distance="2 mi" />
  4. </markers>
  5.  
The error that Javascript debugger throws at me is:
"uncaught exception TypeError: Cannot call method 'getElementsByTagName' of undefined"
Any help would be appreciated!
Apr 6 '09 #1
5 2867
I posted a dupe somehow...
Apr 6 '09 #2
I put the files online, so it might be a little easier to troubleshoot.
Here is the URL: http://nike1984.brinkster.net/Map.aspx
Thank you,
Nick
Apr 6 '09 #3
acoder
16,027 Expert Mod 8TB
Looking at the page source, perhaps the problem is that the Google Maps code is included outside the head and there's no html tag.
Apr 7 '09 #4
That's correct acoder.
I just fixed the following problem by simply moving the first script link within the header section and also adding the doctype and validating the html.
Thank you so much!
Nick
Apr 7 '09 #5
acoder
16,027 Expert Mod 8TB
You're welcome. Glad you got it working :)
Apr 7 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Sean | last post by:
Have you ever wanted to add the great features inherent in Google Maps? Here is how you do it. ============== == STEP ONE == ============== Create a new MS Access form called frmGoogleMap....
18
by: Chris Ianson | last post by:
Hi geniuses (or is that genii, or genies) The challenge is as above really. I have a page with an iframe in it, and need to call a JS function in the *parent* page, *from* inside the iframe. ...
4
by: Navodit | last post by:
Can anyone recommend a good starting tutorial for Javascript? Basically I want to learn enough of Javascript so that I can work with Google Maps API...
3
by: Mr. Roper | last post by:
I'm pretty weak when it comes to Java script, hopefully someone will take mercy on my sole and explain this to me. How come on the following HTML page, when I have my first script tag commented...
3
by: Harch84 | last post by:
Hi I am using a javascript for google maps to geocode two locations and I thin want to retrieve the two coordinates and enter them into a Perl Script. Now I have managed to set up the page with the...
1
by: Harch84 | last post by:
Hi guys I have a script that uses the google maps geocoder and a html form to pass the javascript variable so to perl. Now all of this seems to work fine in mozilla firefoz and internet explorer...
5
by: Chamnap | last post by:
Javascript has no ways to load a script dynamically when the page is already loaded? Thanks Chamnap
2
by: sarah.kidd | last post by:
Hello I was wondering if someone could please help me. I have created a google map: http://www.cancerpatientgis.com/markers%20test/HospPat_markerstest.html
0
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.