473,382 Members | 1,736 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,382 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 2905
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.