Click here to Skip to main content
15,889,867 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have an xml file which has latitude and longitude values saved in it. From my code behind i have successfully read xml file. I had applied for loop and read the coordinates. i save lat and longs in 2 variables l1 and l2.
below is code:

VB
Protected Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

       Dim xmldoc As New XmlDataDocument()

       Dim fs As New FileStream("D:/output.xml", FileMode.Open, FileAccess.Read)
       xmldoc.Load(fs)
       XmlNode = xmldoc.GetElementsByTagName("Table")
       For i = 0 To XmlNode.Count - 1

           d = XmlNode(i).ChildNodes.Item(0).InnerText.Trim()
           coord = XmlNode(i).ChildNodes.Item(1).InnerText.Trim() & "," & XmlNode(i).ChildNodes.Item(2).InnerText.Trim()

           l1 = XmlNode(i).ChildNodes.Item(1).InnerText.Trim()
           l2 = xmlnode(i).ChildNodes.Item(2).InnerText.Trim().

I pass this l1 and l2 value in javascript which plot them on map.
Below is js function:

   function initialize() {
                  
                       var lat = '<%=l1%>';
                       var lon = '<%=l2%>';
                       var myLatlng = new google.maps.LatLng(lat, lon) // This is used to center the map to show our markers
                       var mapOptions = {
                           center: myLatlng,
                           zoom: 3,
                           mapTypeId: google.maps.MapTypeId.ROADMAP,
                           marker: true
                       };
                       var map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);

                       var marker = new google.maps.Marker({
                           position: myLatlng
                       });

                       marker.setMap(map);
                   }

Problem is that it reads all value but plots only last lat long value. How to make it plot all values in xml.

Below is xml:
VB
<newdataset>
  <xs:schema id="NewDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
    <xs:element name="NewDataSet" msdata:isdataset="true" msdata:usecurrentlocale="true">
      <xs:complextype>
        <xs:choice minoccurs="0" maxoccurs="unbounded">
          <xs:element name="Table">
            <xs:complextype>
              <xs:sequence>
                <xs:element name="id" type="xs:int" minoccurs="0" />
                <xs:element name="lat" type="xs:double" minoccurs="0" />
                <xs:element name="long" type="xs:double" minoccurs="0" />
              </xs:sequence>
            </xs:complextype>
          </xs:element>
        </xs:choice>
      </xs:complextype>
    </xs:element>
  </xs:schema>
  <table>
    <id>1</id>
    <lat>41.037930622465289</lat>
    <long>29.428253173828125</long>
  </table>
  <table>
    <id>2</id>
    <lat>40.896905775860006</lat>
    <long>30.477447509765625</long>
  </table>
 <table>
    <id>3</id>
    <lat>18.896905775860006</lat>
    <long>72.477447509765625</long>
  </table>
</newdataset>
Posted
Updated 2-Apr-13 3:35am
v3

1 solution

The reason only the last value is being displayed is simply because that IS the current value of l1 and l2 when it is rendered.
Like this
Iterations
1. l1=41.037930622465289 l2=29.428253173828125
2. l1=40.896905775860006 l2=30.477447509765625
3. l1=18.896905775860006 l2=72.477447509765625
When used in the javascript, its the 3rd iteration value that is being used
The solution you want depends on some info that you have not provided.
 
Share this answer
 
v2
Comments
Jignesh Khant 3-Apr-13 1:08am    
what info?
Hariharan Arunachalam 3-Apr-13 2:07am    
The simplest solution to directly solve your problem is to load the values into an array in asp.net and use that array values in javascript. However, depending on what you actually intending to do, you might try loading a KML file instead (if changes are going to be in bulk) or using AJAX to retrieve the value from the server (if changes are expected dynamically).
Jignesh Khant 4-Apr-13 1:28am    
can you show me what are you trying to tell using my project above?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900