gpt4 book ai didi

安卓谷歌地图 v2 : How to add marker with multiline snippet?

转载 作者:IT老高 更新时间:2023-10-28 13:18:39 28 4
gpt4 key购买 nike

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

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

我希望 fragment 看起来像这样:

| HEADER |
|foo |
|bar |

但是当我尝试将 snippetText 设置为“foo\n bar”时,我只看到 foo bar 并且我不知道如何使它成为多行。你能帮帮我吗?

最佳答案

我已经完成了如下最简单的方法:

private GoogleMap mMap;

Google map 添加 标记:

LatLng mLatLng = new LatLng(YourLatitude, YourLongitude);

mMap.addMarker(new MarkerOptions().position(mLatLng).title("My Title").snippet("My Snippet"+"\n"+"1st Line Text"+"\n"+"2nd Line Text"+"\n"+"3rd Line Text").icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_RED)));

然后在 Google Map 上为 InfoWindow adapter 输入以下代码:

mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

@Override
public View getInfoWindow(Marker arg0) {
return null;
}

@Override
public View getInfoContents(Marker marker) {

LinearLayout info = new LinearLayout(mContext);
info.setOrientation(LinearLayout.VERTICAL);

TextView title = new TextView(mContext);
title.setTextColor(Color.BLACK);
title.setGravity(Gravity.CENTER);
title.setTypeface(null, Typeface.BOLD);
title.setText(marker.getTitle());

TextView snippet = new TextView(mContext);
snippet.setTextColor(Color.GRAY);
snippet.setText(marker.getSnippet());

info.addView(title);
info.addView(snippet);

return info;
}
});

希望对你有所帮助。

关于安卓谷歌地图 v2 : How to add marker with multiline snippet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13904651/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com