简体   繁体   English

Google Maps API v3标记是否带有图片以及该图片上方的文字?

[英]Google Maps API v3 marker with image and a text on top of this image?

I'd like to display an image on a marker but on this image I'd like to also place some text (that I need to change dynamically during the life cycle of my application). 我想在标记上显示图像,但是我还要在该图像上放置一些文本(我需要在应用程序的生命周期中动态更改)。

I've tried markerwithlabel and they have two different examples, one with a picture and another with text but I'd like to combine the two to create something similar to this: 我尝试了markerwithlabel ,它们有两个不同的示例,一个带有图片 ,另一个带有文本,但是我想将两者结合起来以创建类似于以下内容的示例:

在此处输入图片说明

Where "Wheeee!" 哪里“啊!” should be specified (and be updatable) as text. 应该以文本形式指定(并且可以更新)。

How can I achieve this? 我该如何实现?

You can use RichMarker from Google Maps Api Libraries . 您可以从Google Maps Api库使用RichMarker You can add any HTML to your marker (as showin in the example here ). 您可以将任何HTML添加到您的标记(如示例舒这里 )。

So in your case, using RichMarker.setContent() (Api reference here ) you would add custom HTML, something like (roughly, from your provided picture example): 因此,在您的情况下,使用RichMarker.setContent()此处为 Api参考),您将添加自定义HTML,例如(大致来自提供的图片示例):

myMarker.setContent('<div class="callout_bubble">
                       <i class="some_icon"></i>
                       <span class="inside_text" id="my_marker_X_text">Wheee!</span>
                     </div>');

And then add css styles to style it any way you want. 然后添加css样式以您想要的任何方式设置样式。 Also you can change text inside <span> with id my_marker_X_text using js. 您也可以使用js更改ID为my_marker_X_text <span>内的文本。 If you want multiple markers just assign them multiple unique ids, or always change whole content of marker, that's up to you. 如果您想要多个标记,只需为其分配多个唯一的ID,或者始终更改标记的全部内容,这取决于您。

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

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