作者热门文章
- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
有人知道如何将多行代码段添加到 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/
leaflet:一个开源并且对移动端友好的交互式地图 JavaScript 库 中文文档: https://leafletjs.cn/reference.html 官网(英文): ht
我是一名优秀的程序员,十分优秀!