google地圖利用xml載入地標

來源:互聯網
上載者:User

1,申請一個google地圖的key值

2.在頁面中加入下面代碼

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <title></title>
    <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;sensor=true&amp;key=ABQIAAAA6rIhAIUU1yhwWA2eg_PwYBRnwBJdw5wBookTSWhFN0HvJ74Z5hSvi4e0IHlXX8RWKu14CP79FhJWog&h1=ZH" type="text/javascript"></script>
    <script language="javascript" type="text/javascript" >
        var map;
        var geoXml;
        function initialize() {
            if (GBrowserIsCompatible()) {
                geoXml = new GGeoXml("http://www.*****.com/data.xml" + "?rnd=" + Math.random());
                map = new GMap2(document.getElementById("map_canvas"));
                map.enableScrollWheelZoom();
                var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10, 10));
                map.addControl(new GLargeMapControl(),bottomRight);
                map.addControl(new GMapTypeControl());
                //座標點:(緯度,經度)
                map.setCenter(new GLatLng(39.904, 116.389), 11);
                map.openInfoWindow(map.getCenter(), document.createTextNode("Hello, world"));
            }
        }
    </script>
</head>
<body onload ="initialize();" onunload ="GUnload();" >
<div id="map_canvas" style ="width:523px;height:305px;"></div>
</body>
</html>

 

3.data.xml資料格式如下

<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://earth.google.com/kml/2.1">
  <Document>
    <Style id="highlightPlacemark">
      <IconStyle>
        <Icon>
          <href>http://maps.google.com/mapfiles/kml/paddle/red-stars.png</href>
        </Icon>
      </IconStyle>
    </Style>
    <Placemark>
      <name>國家大劇院</name>
      <styleUrl>#highlightPlacemark</styleUrl>
      <description>
        <![CDATA[
          <h1>CDATA Tags are useful!</h1>
          <p><font color="red">CHINA中 國 is <i>more readable</i> and 
          <b>easier to write</b> when you can avoid using entity 
          references.</font></p>
        ]]>
      </description>
      <Point>
        <coordinates>
          116.389751,39.904729
        </coordinates>
      </Point>
    </Placemark>
  </Document>
  <!--說明:設定位置時,先徑度,後緯度和js設定中心SetCenter相反 -->
</kml>

4.運行,ok

源檔案下載點擊這裡:/Files/wenming205/google地圖使用xml載入地標.rar

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.