谷歌地图,JavaScript [英] Google Map, JavaScript

查看:79
本文介绍了谷歌地图,JavaScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml文件,其中保存了纬度和经度值。从我的代码背后我已成功读取xml文件。我申请了循环并读取了坐标。我将lat和long保存在2个变量l1和l2中。

以下是代码:



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:

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);
                   }



问题是它读取了所有值,但是只绘制了最后一个lat long值。如何使它以xml绘制所有值。



以下是xml:


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:

<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>

推荐答案

仅显示最后一个值的原因仅仅是因为它是l1的当前值和l2渲染时。

喜欢这个

迭代次数

1. l1 = 41.037930622465289 l2 = 29.428253173828125

2. l1 = 40.896905775860006 l2 = 30.477447509765625

3. l1 = 18.896905775860006 l2 = 72.477447509765625

在javascript中使用时,它正在使用的第三个迭代值

解决方案你想要的取决于你没有提供的一些信息。
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.


这篇关于谷歌地图,JavaScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆