谁知道如何将多行代码片段添加到Google Maps标记?这是我添加标记的代码:
map.getMap().addMarker(new MarkerOptions()
.position(latLng()).snippet(snippetText)
.title(header).icon(icon));
我希望代码片段看起来像这样:
| HEADER |
|foo |
|bar |
但是当我试图将snippetText设置为"foo \n bar“时,我只看到了foo bar
,并且我不知道如何使其成为多行。你能帮帮我吗?
发布于 2015-08-06 17:33:59
按照安德鲁·S的建议在Hiren Patel's answer上构建:
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;
}
});
发布于 2020-07-23 02:58:08
相同的代码,但在Kotlin中:
mMap?.setInfoWindowAdapter(object : InfoWindowAdapter {
override fun getInfoWindow(arg0: Marker): View? {
return null
}
override fun getInfoContents(marker: Marker): View {
val info = LinearLayout(applicationContext)
info.orientation = LinearLayout.VERTICAL
val title = TextView(applicationContext)
title.setTextColor(Color.BLACK)
title.gravity = Gravity.CENTER
title.setTypeface(null, Typeface.BOLD)
title.text = marker.title
val snippet = TextView(applicationContext)
snippet.setTextColor(Color.GRAY)
snippet.text = marker.snippet
info.addView(title)
info.addView(snippet)
return info
}
})
发布于 2018-07-25 17:39:39
新建(mMap.setOnMapClickListener GoogleMap.OnMapClickListener() {
@Override
public void onMapClick(LatLng point) {
// Already two locations
if (markerPoints.size() > 1) {
markerPoints.clear();
mMap.clear();
}
// Adding new item to the ArrayList
markerPoints.add(point);
// Creating MarkerOptions
MarkerOptions options = new MarkerOptions();
// Setting the position of the marker
options.position(point);
if (markerPoints.size() == 1) {
options.icon(BitmapDescriptorFactory.fromResource(R.mipmap.markerss)).title("Qtrip").snippet("Balance:\nEta:\nName:");
options.getInfoWindowAnchorV();
} else if (markerPoints.size() == 2) {
options.icon(BitmapDescriptorFactory.fromResource(R.mipmap.markerss)).title("Qtrip").snippet("End");
}
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;
}
});
mMap.addMarker(options);
https://stackoverflow.com/questions/13904651
复制相似问题