源码是这样写标注的,不过它在地图上展示的是图标。
code:
var er0 = new google.maps.Marker
({
position: lat,
icon:image,
title: v.COMMUNITY_QUANPIN
 });
er0.setMap(map); 
想问问怎么写让图标变成文字显示?是调用其它的类,还是er的其他属性有我不知道,求高手告知,小弟感激不尽!
因为曾经老是给100分,现在穷了- -只能把剩余的分数全部贡献了
 

解决方案 »

  1.   

    Marker都是图片或者图形的,没文字描述的,你可以设置Marker的icon属性为一张文字的图片来模拟就行了吧。。 var mk = new google.maps.Marker({
                position: myLatLng,
                map: map,
                icon: '文字内容的png图片'
            });
      

  2.   


    嗯,这个icon我知道,但是文字内容的图片不可能做出好多张吧。现在正在用自定义的叠加层尝试,目前卡在了点击事件的绑定上了。谢谢回复
      

  3.   

    心态还是不到家- -结果浪费了不少时间,现在共享研究成果,可以实现图标上加文字
    用到的google地图的技术是:自定义叠加层,code如下:/***************自定义叠加层,可作为站点显示在地图上******************/  
    function MyMarker(map,options) {     
      // Now initialize all properties.     
      this.latlng = options.latlng; //设置图标的位置  
      this.labelText = options.labelText || '标记';  
      this.labelClass = options.labelClass || 'shadow';//设置文字的样式  
      this.map_ = map;        this.div_ = null;     
      // Explicitly call setMap() on this overlay     
      this.setMap(map);   
    }   
    MyMarker.prototype = new google.maps.OverlayView();  
    //初始化图标  
    MyMarker.prototype.onAdd = function() {      
    // Note: an overlay's receipt of onAdd() indicates that    
    // the map's panes are now available for attaching     
    // the overlay to the map via the DOM.      
    // Create the DIV and set some basic attributes.    
    var div = document.createElement('DIV'); //创建存放图片和文字的div  
    div.style.border = "none";     
    div.style.borderWidth = "0px";     
    div.style.position = "absolute";  
    div.style.cursor = "hand";  
    //初始化文字标签  
    var label = document.createElement('DIV');//创建文字标签  
    label.className = this.labelClass;  
    label.innerHTML = this.labelText;  
    label.style.position = 'absolute';  
    label.style.width = '200px';  
    label.style.fontWeight = "bold";  
    label.style.textAlign = 'left';  
    label.style.padding = "2px";  
    label.style.fontSize = "10px";  
      
    div.appendChild(label);     
      
    this.div_ = div;     
    var panes = this.getPanes();    
    panes.overlayLayer.appendChild(div);   
    }  
    //绘制图标,主要用于控制图标的位置  
    MyMarker.prototype.draw = function(){         
      var overlayProjection = this.getProjection();       
      var position = overlayProjection.fromLatLngToDivPixel(this.latlng);   //将地理坐标转换成屏幕坐标  
      var div = this.div_;    
      div.style.left =position.x-5 + 'px';    
      div.style.top  =position.y-5 + 'px';    
      //控制图标的大小  
      div.style.width = '10px';    
      div.style.height ='10px';  
    }  
    MyMarker.prototype.onRemove = function() {     
      this.div_.parentNode.removeChild(this.div_);     
      this.div_ = null;   
    }  
    //Note that the visibility property must be a string enclosed in quotes   
    MyMarker.prototype.hide = function(){     
      if (this.div_) {       
    this.div_.style.visibility = "hidden";     
      }   
    }    
    MyMarker.prototype.show = function(){     
      if (this.div_) {       
      this.div_.style.visibility = "visible";     
      }   
    }   
    //显示或隐藏图标  
    MyMarker.prototype.toggle = function(){     
    if (this.div_) {       
    if (this.div_.style.visibility == "hidden") {         
    this.show();       
    } else {         
    this.hide();       
    }     
    }  
    }  
    页面这么引用,就可以实现气泡效果
    var lat= new google.maps.LatLng(v.BAIDU_LATITUDE,v.BAIDU_LONGITUDE);
    var contentString = '<div id="'+v.COMMUNITY_ID+'"></div><a href="" ><p>'+v.COMMUNITY_QUANPIN +'</p><p>'+v.FULL_VIEW_PATH+'</p></a>';//点击地图标记弹出的内容

    var infowindow = new google.maps.InfoWindow
    ({
    content: contentString
    });
    var overlay = new MyMarker(map,{latlng:lat,labelText:v.COMMUNITY_QUANPIN});

    var er0 = new google.maps.Marker
    ({
    position: lat,
    title: v.COMMUNITY_QUANPIN,
    map:map,
    icon:image
     });
     
    google.maps.event.addListener(er0,'click',function()
    {
    if(infowindow0)
    {
    infowindow0.close();
    }
    getHouse(v.COMMUNITY_ID);
    infowindow.open(map,er0);
    infowindow0=infowindow;
    })
    有啥不懂得可以联系我QQ767385447,我可是把谷歌v3的文档给全看完了啊- -