unc*_*Lem 64 android google-maps
有人知道如何将多行代码段添加到Google地图标记吗?这是我添加标记的代码:
map.getMap().addMarker(new MarkerOptions()
.position(latLng()).snippet(snippetText)
.title(header).icon(icon));
Run Code Online (Sandbox Code Playgroud)
我想要片段看起来像这样:
| HEADER |
|foo |
|bar |
Run Code Online (Sandbox Code Playgroud)
但是当我试图将snippetText设置为"foo \n bar"时,我看到了foo bar,我没有任何想法如何使它成为多线.你能帮助我吗?
Hir*_*tel 115
我用最简单的方式做了如下:
private GoogleMap mMap;
Run Code Online (Sandbox Code Playgroud)
虽然添加 标记在谷歌地图:
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)));
Run Code Online (Sandbox Code Playgroud)
之后在Google Map上放置InfoWindow 适配器的代码:
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;
}
});
Run Code Online (Sandbox Code Playgroud)
希望它会对你有所帮助.
Nub*_*per 15
建立在Hiren Patel的回答上,Andrew S建议:
mMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {
@Override
public View getInfoWindow(Marker arg0) {
return null;
}
@Override
public View getInfoContents(Marker marker) {
Context context = getApplicationContext(); //or getActivity(), YourActivity.this, etc.
LinearLayout info = new LinearLayout(context);
info.setOrientation(LinearLayout.VERTICAL);
TextView title = new TextView(context);
title.setTextColor(Color.BLACK);
title.setGravity(Gravity.CENTER);
title.setTypeface(null, Typeface.BOLD);
title.setText(marker.getTitle());
TextView snippet = new TextView(context);
snippet.setTextColor(Color.GRAY);
snippet.setText(marker.getSnippet());
info.addView(title);
info.addView(snippet);
return info;
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
67777 次 |
| 最近记录: |