Android Google Maps v2:如何使用多行代码段添加标记? [英] Android Google Maps v2: How to add marker with multiline snippet?

查看:28
本文介绍了Android Google Maps v2:如何使用多行代码段添加标记?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何将多行代码段添加到 Google 地图标记吗?这是我添加标记的代码:

Does anybody know how to add multiline snippet to Google Maps marker? That's my code for adding markers:

map.getMap().addMarker(new MarkerOptions()
    .position(latLng()).snippet(snippetText)
    .title(header).icon(icon));

我希望代码片段看起来像这样:

I want snippet to look like this:

| HEADER |
|foo     |
|bar     |

但是当我尝试将snippetText设置为foo bar"时,我只看到了 foo bar 并且我没有任何想法如何使它成为多行.你能帮我吗?

but when I'm trying to set snippetText to "foo bar", I see just foo bar and I don't have any ideas how to make it multiline. Can you help me?

推荐答案

看来您需要创建自己的信息窗口"内容才能完成这项工作:

It looks like you will need to create your own "info window" contents to make that work:

  1. 创建覆盖 getInfoContents()InfoWindowAdapter 实现以返回您想要进入 InfoWindow 框架的内容

  1. Create an implementation of InfoWindowAdapter that overrides getInfoContents() to return what you want to go into the InfoWindow frame

在您的 GoogleMap 上调用 setInfoWindowAdapter(),传递您的 InfoWindowAdapter

Call setInfoWindowAdapter() on your GoogleMap, passing an instance of your InfoWindowAdapter

此示例项目演示了该技术.用 "foo bar" 替换我的片段可以正确处理换行符.然而,更有可能的是,您只会想出一个不需要换行符的布局,在您想要的视觉结果中为每一行使用单独的 TextView 小部件.

This sample project demonstrates the technique. Replacing my snippets with "foo bar" correctly processes the newline. However, more likely, you will just come up with a layout that avoids the need for the newline, with separate TextView widgets for each line in your desired visual results.

这篇关于Android Google Maps v2:如何使用多行代码段添加标记?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆