简体   繁体   English

我们如何在 google map api 中通过 javascript 设置标记标签内容?

[英]how we set marker label content by javascript in google map api?

I am using this code this code to change label text of marker label in google map api.我正在使用此代码此代码来更改 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?请有人让我知道我的代码有什么问题吗?

Try:尝试:

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

Reading through the marker label source code , the MarkerLabel object extends from google.maps.Marker.通读标记标签源代码,MarkerLabel 对象从 google.maps.Marker 扩展而来。

Whenever you call the .set() method on the MarkerLabel object, an event is raised which refreshes the marker.每当您在 MarkerLabel 对象上调用.set()方法时,都会引发一个刷新标记的事件。

So calling marker.set('labelContent', 'sdda');所以调用marker.set('labelContent', 'sdda'); will raise a 'labelcontent_changed' event, which in turn makes the marker set it's inner content this.setContent()将引发一个'labelcontent_changed'事件,这反过来使标记设置它的内部内容this.setContent()

Here is an excerpt from the source code:以下是源代码的摘录:

@class This class represents the optional parameter passed to the {@link MarkerWithLabel} constructor. @class 此类表示传递给 {@link MarkerWithLabel} 构造函数的可选参数。 The properties available are the same as for google.maps.Marker with the addition of the properties listed below.可用的属性与google.maps.Marker相同,但添加了下面列出的属性。 To change any of these additional properties after the labeled marker has been created, call google.maps.Marker.set(propertyName, propertyValue) .要在创建标记标记后更改任何这些附加属性,请调用google.maps.Marker.set(propertyName, propertyValue)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM