Aks*_*ari 5 android google-maps google-maps-markers
我正在开发一个使用 Google 地图 Android API 的 Android 应用程序。我在地图上显示多个标记,我想在每个标记旁边显示一个标签,如下图所示,但我不知道该怎么做它。
我已经浏览了https://developers.google.com/maps/documentation/android-api/map-with-marker上的 Google 地图文档 ,但我无法找到有关如何以这种方式显示标签的详细信息。I已尝试打开弹出窗口的标题属性,但我需要它来显示有关我的标记的详细视图(信息窗口),并且我需要显示主标题而不打开任何标记的弹出窗口
知道如何按照附图所示的方式添加标记吗?
不确定这是否是您的想法,但这里是
创建MarkerOptions对象:
MarkerOptions options = new MarkerOptions()
.title(name)
.position(source)
.icon(gettIconFromDrawable(myMarker))
.snippet("Briefly describe \nyour content here");
Run Code Online (Sandbox Code Playgroud)
然后将标记添加到地图上
Marker sourceMarker = mMap.addMarker(options);
Run Code Online (Sandbox Code Playgroud)
创建InfoWindowAdapter以容纳片段中的多行。(原答案在这里)
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)
最后,添加此属性以确保标记保持可见
sourceMarker.showInfoWindow();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3504 次 |
| 最近记录: |