Android的谷歌地图V2:如何添加标记具有多行代码段?有多、标记、代码、地图

2023-09-05 06:08:48 作者:旧知己

有谁知道如何多行代码片段添加到谷歌地图标记?这是我的$ C $下添加标记:

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为福\ñ吧,我看到的只是富巴和我没有任何想法如何使它多行。你能帮助我吗?

but when I'm trying to set snippetText to "foo \n 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:

创建 InfoWindowAdapter 的实现,将覆盖 getInfoContents()返回你想进入什么在信息窗口

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

呼叫 setInfoWindowAdapter() GoogleMap的,传递你的 InfoWindowAdapter

此示例项目演示了该技术。与FOO \ NBAR更换我的片段正确处理新行。然而,更可能的是,你一定会拿出一个布局,避免了换行,有独立的的TextView 小部件在您所需的视觉效果每行

This sample project demonstrates the technique. Replacing my snippets with "foo\nbar" 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.