完整代码: <html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"></link> <style>
.hotel {border:solid 1px #000000;padding-left:1em; display:block; width:60px;cursor:pointer;margin:5px;} 
div.erLabel {
display: block;
padding-top: 9px;
text-align: center;
color:blue;
width: 32px;
letter-spacing: 0px;
font-size: 12px;
font-family: Arial;
}
</style> <script
src="http://ditu.google.com/maps?file=api&amp;v=2&amp;key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA&hl=zh-CN"
type="text/javascript"></script> <script type="text/javascript">
        var cenx = 39.990168;
        var ceny = 116.295304;
        var stzoom=13;
        var map;
        var arySite = new Array();
        
       // 自定义标记
        function LabeledMarker(latlng, options){
    this.latlng = latlng;
    this.labelText = options.labelText || "";
    this.labelClass = options.labelClass || "erLabel";
    this.labelOffset = options.labelOffset || new GSize(0, 0);
    GMarker.apply(this, arguments);
}
        
        LabeledMarker.prototype = new GMarker(new GLatLng(0, 0));
        
        LabeledMarker.prototype.initialize = function(map) {
GMarker.prototype.initialize.call(this, map);

var div = document.createElement("div");
div.className = this.labelClass;
div.innerHTML = this.labelText;
div.style.position = "absolute";
map.getPane(G_MAP_MARKER_PANE).appendChild(div);

this.map = map;
this.div = div;
}

LabeledMarker.prototype.redraw = function(force) {
GMarker.prototype.redraw.call(this, map); if (!force) return;

var p = this.map.fromLatLngToDivPixel(this.latlng);
var z = GOverlay.getZIndex(this.latlng.lat());

this.div.style.left = (p.x + this.labelOffset.width) + "px";
this.div.style.top = (p.y + this.labelOffset.height) + "px";
this.div.style.zIndex = z + 1; 
} LabeledMarker.prototype.remove = function() {
  this.div.parentNode.removeChild(this.div);
  this.div = null;
  GMarker.prototype.remove.call(this);
} function addHotel(map, siteCode, siteDesc, lat, lng, address) {
var icon=new GIcon();
icon.image="http://labs.google.com/ridefinder/images/mm_20_green.png";
icon.iconSize = new GSize(16,16);
icon.iconAnchor = new GPoint(8,8);
icon.infoWindowAnchor = new GPoint(8, 8);

var  = new LabeledMarker(
new GLatLng(lat,lng), 
{icon:icon, title:siteDesc,draggable: true,labelText:siteDesc}
);

arySite[siteCode] = ;
map.addOverlay();
GEvent.addListener(, "click", function() {.openInfoWindowHtml('名称:'+siteDesc+'<br />地址:'+address);}); 
GEvent.addListener(, "mouseover", function() {

document.getElementById('hotel'+siteCode).style.background='yellow';
}); 
GEvent.addListener(, "mouseout", function() {

document.getElementById('hotel'+siteCode).style.background='white';
}); 
}
        function init(){
         //检查浏览器的兼容性.
            if (GBrowserIsCompatible()){
                map=new GMap2(document.getElementById("map"));
                
//设置地图的中心坐标.
                var loc = new GLatLng(cenx,ceny);
                map.setCenter(loc,stzoom);
                
              map.addControl(new GLargeMapControl());

map.addControl(new GMapTypeControl());

addHotel(map,4,'歌华',cenx-0.020,ceny-0.009,'北京大学北门');
addHotel(map,5,'开元',cenx+0.010,ceny+0.001,'北京市天华门3号');
addHotel(map,6,'华天',cenx-0.010,ceny+0.017,'北京市天河华贵45号');
     }
 }
 
        //初始化地图
        window.onload=init; 
        //卸载地图
        window.onunload=GUnload;    </script> </head>
<body>
<!-- 地图画板 -->
<div id="map" style="width: 800px; height: 500px; float:left;"></div>
<div id="hotellist" style="float:left;" >
<span class='hotel' id='hotel4' onclick='GEvent.trigger(arySite[4],"click")' onmouseover='GEvent.trigger(arySite[4],"mouseover")' onmouseout='GEvent.trigger(arySite[4],"mouseout")'>歌华</span>
<span class='hotel' id='hotel5' onclick='GEvent.trigger(arySite[5],"click")' onmouseover='GEvent.trigger(arySite[5],"mouseover")' onmouseout='GEvent.trigger(arySite[5],"mouseout")'>开元</span>
<span class='hotel' id='hotel6' onclick='GEvent.trigger(arySite[6],"click")' onmouseover='GEvent.trigger(arySite[6],"mouseover")' onmouseout='GEvent.trigger(arySite[6],"mouseout")'>华天</span>
</div>
</body>
</html>
---------------------------------------------------------------------------------------------
标记可显示文字 ,但是标记设置了可移动:draggable: true 移动时文字不随图标移动,
请问怎么解决????????

解决方案 »

  1.   

    建议去google Map的论坛看看,
      

  2.   

    不要完整的   要关键代码    google API
      

  3.   


    关键的就在自定义哪里 懂的一看就知道了
     // 自定义标记
      function LabeledMarker(latlng, options){
    this.latlng = latlng;
    this.labelText = options.labelText || "";
    this.labelClass = options.labelClass || "erLabel";
    this.labelOffset = options.labelOffset || new GSize(0, 0);
    GMarker.apply(this, arguments);
    }
        
      LabeledMarker.prototype = new GMarker(new GLatLng(0, 0));
        
      LabeledMarker.prototype.initialize = function(map) {
    GMarker.prototype.initialize.call(this, map);var div = document.createElement("div");
    div.className = this.labelClass;
    div.innerHTML = this.labelText;
    div.style.position = "absolute";
    map.getPane(G_MAP_MARKER_PANE).appendChild(div);this.map = map;
    this.div = div;
    }LabeledMarker.prototype.redraw = function(force) {
    GMarker.prototype.redraw.call(this, map);if (!force) return;var p = this.map.fromLatLngToDivPixel(this.latlng);
    var z = GOverlay.getZIndex(this.latlng.lat());this.div.style.left = (p.x + this.labelOffset.width) + "px";
    this.div.style.top = (p.y + this.labelOffset.height) + "px";
    this.div.style.zIndex = z + 1;  
    }LabeledMarker.prototype.remove = function() {
    this.div.parentNode.removeChild(this.div);
    this.div = null;
    GMarker.prototype.remove.call(this);
    }
      

  4.   

    去掉 title:siteDesc 还是一样···