google地图利用xml加载地标

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

你可能感兴趣的:(google地图)