【问题标题】:How to parse xml coordinates onto google map如何将xml坐标解析到谷歌地图上
【发布时间】:2013-08-19 19:19:36
【问题描述】:

到目前为止,我所做的是使用By google documentation 提供的说明从 JSON 文件中解析数据。我的问题是我需要为我的代码更改什么,以便我可以从 xml 文件中解析数据?

我还想在信息窗口中添加内容。我在正确的轨道上吗?

我当前的代码。

<!DOCTYPE html>
    <html>
      <head>
        <style>
          html, body, #map_canvas { margin: 0; padding: 0; height: 100%; }
        </style>
        <script
          src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=visualization">
        </script>


        <script>
         var map;
        function initialize() {
        var mapOptions = {
        zoom: 5,
        center: new google.maps.LatLng(-27.48939, 153.012772),
        mapTypeId: google.maps.MapTypeId.ROADMAP 
      };
      map = new google.maps.Map(document.getElementById('map_canvas'),
          mapOptions);

      var script = document.createElement('script');
      script.src = 'http://earthquake.usgs.gov/earthquakes/feed/geojsonp/2.5/week';
      document.getElementsByTagName('head')[0].appendChild(script);
    }

    window.eqfeed_callback = function(results) {
      for (var i = 0; i < results.features.length; i++) {

        var earthquake = results.features[i]; 
        var coords = earthquake.geometry.coordinates; 

        var latLng = new google.maps.LatLng(coords[1],coords[0]); 

        var marker = new google.maps.Marker({
          position: latLng,
          map: map,

        });

        var infowindow = new google.maps.InfoWindow({
        content: "<div>Hello! World</div>",
        maxWidth:100
        });

        google.maps.event.addListener(marker, "mouseover", function() {
            infowindow.open(this, marker);
        });

      }
    }


      </script>
      </head>

      <body onload="initialize()">
        <div id="map_canvas"></div>
      </body>

      </html>

【问题讨论】:

  • 您认为为什么需要使用 XML?

标签: xml json parsing google-maps-api-3 xml-parsing


【解决方案1】:

My question is what do i need to change for my codes so that i can parse data out of a xml file instead ?

您不需要将 JSON 更改为 XML。您可以对从 XML 加载的数据执行的任何操作,都可以对从 JSON 加载的数据执行任何操作。

【讨论】:

  • 感谢 geocodezip。只是另一个快速的问题。我正在尝试从外部来源为我的信息窗口检索动态内容信息。根据我在这里的情况,我该如何实现? var infowindow = new google.maps.InfoWindow({content: "&lt;div&gt;Hello! World&lt;/div&gt;",maxWidth:100});google.maps.event.addListener(marker, "mouseover", function(){infowindow.open(this, marker); });
  • 是的。就是这样。
  • 在浏览器中查看源代码(在我查看的所有浏览器中都是 Ctrl-U)
猜你喜欢
  • 2013-10-12
  • 1970-01-01
  • 2013-08-30
  • 1970-01-01
  • 1970-01-01
  • 2012-04-06
  • 2015-02-05
  • 2012-10-18
相关资源
最近更新 更多