473,406 Members | 2,281 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,406 software developers and data experts.

Google Map only display certain XML information

Hi there, I'm busy making a site that displays markers and info from an xml file on a map. I'm at the point where all markers stored in the xml file are displayed on the map, but I only want certain ones to be displayed. Each marker has a date associated with it, and I only want to display markers which match today's date.

Here is the script in my document head:

Expand|Select|Wrap|Line Numbers
  1. <script>
  2.      var map;
  3.  
  4.      function load() {  
  5.       if (GBrowserIsCompatible()) {
  6.          map = new GMap2(document.getElementById("map"));
  7.          map.setCenter(new GLatLng(51.500152, -0.126236), 11);  
  8.      map.addControl(new GSmallMapControl());
  9.      map.getPane(G_MAP_FLOAT_SHADOW_PANE).style.display = "none";
  10.      G_NORMAL_MAP.getMinimumResolution = function () { return 12 }; 
  11.  
  12.      addMarkersFromXML();
  13.  
  14.       }
  15.  
  16.       }
  17.  
  18.  
  19.       function addMarkersFromXML(){
  20.        var batch = [];
  21.        mgr = new MarkerManager(map); 
  22.  
  23.        var request = GXmlHttp.create();
  24.        request.open('GET', 'data.xml', true);
  25.        request.onreadystatechange = function() {
  26.          if (request.readyState == 4 && request.status == 200) {
  27.         var xmlDoc = request.responseXML;
  28.         var xmlrows = xmlDoc.documentElement.getElementsByTagName("Row");
  29.  
  30.         for (var i = 0; i < xmlrows.length; i++) {
  31.             var xmlrow = xmlrows[i];
  32.  
  33.             var xmlcellLongitude = xmlrow.getElementsByTagName("Longitude")[0];
  34.             var xmlcellLatitude = xmlrow.getElementsByTagName("Latitude")[0];
  35.             var point = new GLatLng(parseFloat(xmlcellLatitude.firstChild.data), parseFloat(xmlcellLongitude.firstChild.data));
  36.  
  37.             //get the building name
  38.             var xmlcellName = xmlrow.getElementsByTagName("Name")[0];
  39.             var celltextName = xmlcellName.firstChild.data;
  40.  
  41.             var xmlcellImage = xmlrow.getElementsByTagName("Image")[0];
  42.             var celltextImage = xmlcellImage.firstChild.data;
  43.  
  44.             //get the address
  45.             var xmlcellGenre = xmlrow.getElementsByTagName("Genre")[0];
  46.             var celltextGenre = xmlcellGenre.firstChild.data;
  47.  
  48.             //get the ownership
  49.             var xmlcellBio = xmlrow.getElementsByTagName("Bio")[0];
  50.             var celltextBio = xmlcellBio.firstChild.data;
  51.  
  52.             var xmlcellSong = xmlrow.getElementsByTagName("Song")[0];
  53.             var celltextSong = xmlcellSong.firstChild.data;
  54.  
  55.             var xmlcellSongtitle = xmlrow.getElementsByTagName("Songtitle")[0];
  56.             var celltextSongtitle = xmlcellSongtitle.firstChild.data;
  57.  
  58.             var xmlcellVenue = xmlrow.getElementsByTagName("Venue")[0];
  59.             var celltextVenue = xmlcellVenue.firstChild.data;
  60.  
  61.             var xmlcellStarttime = xmlrow.getElementsByTagName("Starttime")[0];
  62.             var celltextStarttime = xmlcellStarttime.firstChild.data;
  63.  
  64.             var xmlcellEndtime = xmlrow.getElementsByTagName("Endtime")[0];
  65.             var celltextEndtime = xmlcellEndtime.firstChild.data;
  66.  
  67.             var xmlcellDate = xmlrow.getElementsByTagName("Date")[0];
  68.             var celltextDate = xmlcellDate.firstChild.data;
  69.  
  70.             var marker = createMarker(point,celltextName,celltextImage,celltextGenre,celltextBio,celltextSong,celltextSongtitle,celltextVenue,celltextStarttime,celltextEndtime,celltextDate);
  71.             batch.push(marker);
  72.  
  73.  
  74.         }
  75.  
  76.         mgr.addMarkers(batch,11);
  77.         mgr.refresh();
  78.  
  79.         }
  80.         }
  81.     request.send(null);
  82.  
  83.       }
  84.  
  85.      function createMarker(point,name,image_source,genrevar,bio,song_source,songtitlevar,venuevar,starttime,endtime,datevar) {
  86.            var marker = new GMarker(point);
  87.            GEvent.addListener(marker, "click", function() {
  88.              texttitle.innerHTML=name;
  89.              genre.innerHTML=genrevar;
  90.              text.innerHTML=bio;
  91.              songtitle.innerHTML=songtitlevar;
  92.              document.getElementById('image').src=image_source;
  93.              document.getElementById('audiobutton').style.display='block';
  94.              document.getElementById('audiobutton').src='play.png';
  95.              document.getElementById('audioplayer').src=song_source;
  96.              marker.openInfoWindowHtml('<h>'+name+'</h>'+'<br>'+venuevar+'<br>'+starttime+' - '+endtime);
  97.            });
  98.            return marker;
  99.      }
  100.  
  101.     </script>
  102.  
And here is a sample of the data stored in the xml file:

Expand|Select|Wrap|Line Numbers
  1. <Root>
  2. <Row>
  3. <Longitude>-0.126236</Longitude>
  4. <Latitude>51.500152</Latitude>
  5. <Name>Soundgarden</Name>
  6. <Image>http://www.musicbabylon.com/files/Soundgarden.jpg</Image>
  7. <Genre>Grunge</Genre>
  8. <Bio>Soundgarden is an American rock band formed in Seattle, Washington in 1984 by lead singer and drummer Chris Cornell, lead guitarist Kim Thayil, and bassist Hiro Yamamoto. Matt Cameron became the band's permanent drummer in 1986 while bassist Ben Shepherd became a permanent replacement for Yamamoto in 1990. Soundgarden was one of the seminal bands in the creation of grunge, a style of alternative rock that developed in Seattle, and was one of a number of grunge bands signed to the record label Sub Pop. Soundgarden was the first grunge band to sign to a major label (AM Records, in 1988), though the band did not achieve commercial success until they popularized "grunge" in the early 1990s with Seattle contemporaries Nirvana, Alice in Chains and Pearl Jam.</Bio>
  9. <Song>http://www.pampelmoose.com/audio/Soundgarden-Jesus_Christ_Pose.mp3</Song>
  10. <Songtitle>Jesus Christ Pose</Songtitle>
  11. <Venue>Pub</Venue>
  12. <Starttime>19:00</Starttime>
  13. <Endtime>22:00</Endtime>
  14. <Date>02/10/2010</Date>
  15. </Row>
  16. <Row>
  17. <Longitude>-0.132093</Longitude>
  18. <Latitude>51.501624</Latitude>
  19. <Name>Elliott Smith</Name>
  20. <Image>http://upload.wikimedia.org/wikipedia/commons/7/7c/Elliott_Smith_Memorial_Wall.jpg</Image>
  21. <Genre>Folk</Genre>
  22. <Bio>Steven Paul "Elliott" Smith (August 6, 1969 – October 21, 2003) was an American singer-songwriter and musician. Smith was born in Omaha, Nebraska, raised primarily in Texas, and resided for a significant portion of his life in Portland, Oregon, where he first gained popularity. His primary instrument was the guitar, but he was also proficient at piano, clarinet, bass guitar, drums, and harmonica. Smith had a distinctive vocal style characterized by his "whispery, spiderweb-thin delivery"[1] and use of multi-tracking to create vocal layers, textures, and harmonies. After playing in rock band Heatmiser for several years, Smith began his solo career in 1994 with releases on the independent record labels Cavity Search and Kill Rock Stars. In 1997 he signed a contract with DreamWorks Records, for which he recorded two albums. Smith rose to mainstream prominence when his song "Miss Misery" — included in the soundtrack for the film Good Will Hunting — was nominated for an Oscar in the Best Original Song category in 1998.</Bio>
  23. <Song>http://etpatatietpatata.typepad.com/observing_the_process_wil/files/04_good_to_go.mp3</Song>
  24. <Songtitle>Good To Go</Songtitle>
  25. <Venue>Bar</Venue>
  26. <Starttime>18:30</Starttime>
  27. <Endtime>23:00</Endtime>
  28. <Date>21/10/2010</Date>
  29. </Row>
  30. </Root>
  31.  
So that's it. Does anyone know how I can edit the code to check today's date against the xml file and only display the correct markers? Any help would be greatly appreciated!
Oct 9 '10 #1
1 1834
jkmyoung
2,057 Expert 2GB
You need to somehow get today's date, say it's in variable todaysDate

Expand|Select|Wrap|Line Numbers
  1. var xmlrow = xmlrows[i];
  2. var rowdate = xmlrow.getElementsByTagName("Date")[0].value
  3. if (!rowdate.equals(todaysDate)) continue;
  4.  
Oct 15 '10 #2

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

Similar topics

1
by: Omer Ahmad | last post by:
Hi All, I've been working with python for about 6 months now, and have been very impressed with the size and scope of the libraries. I have, however, run into a bit of a problem. I...
1
by: jm001 | last post by:
Hi, I am creating a database that will hold contact information plus additional information on different tables. ID on contact will auto assign. I want to have the system prompt for ID and...
2
by: Stephen | last post by:
Hi, Suppose there is a column in the dataset that is a very large field (say varchar(500)) and i want to display partial information with (....) so that the user can click on it to view for...
20
by: admyc | last post by:
How can I make google show a link to my website when words are entred into its search field that don't actually appear in the main page of/anywhere in my website. I think these keywords need to...
1
by: Benny Ng | last post by:
Dear All, Now I met one problem in the development of my one application. I have one ASP.NET page. It's for disply the information of customer. But now I have one new requirement. It's to...
1
imrosie
by: imrosie | last post by:
Hello All, I have a combo box that selects a customer and brings up all of the data associated with that customer (Billing data (on Main form), Order data (on Sub form #1) and Shipping Data on Sub...
3
by: Coll | last post by:
I have a form that had been setup with a combo box. You'd select a value from the combo box and a query would open and display matching records. I now need to remove the combo box and set up a text...
8
by: raamay | last post by:
i have a page where i have name of my company staffs and is hyperlinked to another page where all the details of the staffs are present. I mean a page contains only the staffs name and in the other...
1
by: Peter van der Zee | last post by:
L.S., I'm want to fill a Listbox with class Array "records" based on certain criteria. The idea is to be able to select one "record" at the time, modify the data, and display this "changed"...
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.