最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

how we set marker label content by javascript in google map api? - Stack Overflow

programmeradmin0浏览0评论

I am using this code this code to change label text of marker label in google map api. But this code not working.

var marker = new MarkerWithLabel({
        position : latlng,
        draggable : true,
        raiseOnDrag : true,
        map : map,
        labelContent : textVal,
        labelAnchor : new google.maps.Point(22, 0),
        title : "" + textCount,
        labelClass : "someClass" + textCount,
        icon:{}
    });
    marker.setLabelContent("sdda");

please can anybody let me know what's wrong in my code?

I am using this code this code to change label text of marker label in google map api. But this code not working.

var marker = new MarkerWithLabel({
        position : latlng,
        draggable : true,
        raiseOnDrag : true,
        map : map,
        labelContent : textVal,
        labelAnchor : new google.maps.Point(22, 0),
        title : "" + textCount,
        labelClass : "someClass" + textCount,
        icon:{}
    });
    marker.setLabelContent("sdda");

please can anybody let me know what's wrong in my code?

Share Improve this question asked Aug 6, 2014 at 16:30 user3907798user3907798 531 gold badge1 silver badge3 bronze badges
Add a comment  | 

2 Answers 2

Reset to default 13

Try:

marker.set('labelContent', 'sdda');

Reading through the marker label source code, the MarkerLabel object extends from google.maps.Marker.

Whenever you call the .set() method on the MarkerLabel object, an event is raised which refreshes the marker.

So calling marker.set('labelContent', 'sdda'); will raise a 'labelcontent_changed' event, which in turn makes the marker set it's inner content this.setContent()

Here is an excerpt from the source code:

@class This class represents the optional parameter passed to the {@link MarkerWithLabel} constructor. The properties available are the same as for google.maps.Marker with the addition of the properties listed below. To change any of these additional properties after the labeled marker has been created, call google.maps.Marker.set(propertyName, propertyValue).

Try: var label= { color: '#333', fontWeight: 'bold', fontSize: '16px', text: data[i].deviceID.toUpperCase() }; marker.setLabel(label);

发布评论

评论列表(0)

  1. 暂无评论