xml解析地理数据并放置在地图上

时间:2011-10-26 17:41:30

标签: xml google-maps

我做了JS程序,它使用AJAX调用从XML文件中获取所有地理数据点。现在我需要将这些点放在谷歌地图上。我完成了地图的所有编码并让它显示等等,我确实从我的XML中获得了长数和纬数,但是如何在地图中插入这些数字以便显示点?

1 个答案:

答案 0 :(得分:0)

来自Google http://code.google.com/apis/maps/documentation/javascript/examples/marker-simple.html

的示例
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Marker Simple</title>
<link href="http://code.google.com/apis/maps/documentation/javascript/examples/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="//maps.googleapis.com/maps/api/js?sensor=false">    </script>
<script type="text/javascript">
  function initialize() {
    var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
    var myOptions = {
      zoom: 4,
      center: myLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

    var marker = new google.maps.Marker({
        position: myLatlng, 
        map: map,
        title:"Hello World!"
    });   
  }
</script>
</head>
<body onload="initialize()">
  <div id="map_canvas"></div>
</body>
</html>

有很多关于如何使用map api的示例: http://code.google.com/apis/maps/documentation/javascript/examples/index.html