Android Google Maps API v2上带有文字的多个标记

时间:2013-01-13 12:53:37

标签: android google-maps google-maps-android-api-2

我的目标是在Android Google Maps API v2 地图上添加多个带文字的标记。信息窗口方法(showInfoWindow())不合适,因为一次只显示一个信息窗口。例如,我想要这样的东西:enter image description here

正如您所看到的,每个标记都有自己的数据(本例中的数字)始终显示。 如何使用Android Google Maps API v2

实现这一目标

5 个答案:

答案 0 :(得分:10)

要做到这一点,你必须自定义每个标记的图标,使其成为你需要的。 这是链接:https://developers.google.com/maps/documentation/android/marker#customize_a_marker

然后您可以放置​​一些PNG资源(蓝色,黄色和红色),并在运行时获取正确的位图,按代码在位图上写入文本,然后将其设置为{{1的自定义标记方法。

答案 1 :(得分:6)

试试这些链接最好使用&它将有助于如何在Android Google Maps API v2

上添加带有文本的多个标记
  1. Link1
  2. Link2

答案 2 :(得分:3)

试试这个

LinearLayout tv = (LinearLayout) this.getLayoutInflater().inflate(R.layout.marker_dialog, null, false);

tv.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
tv.layout(0, 0, tv.getMeasuredWidth(), tv.getMeasuredHeight());

tv.setDrawingCacheEnabled(true);
tv.buildDrawingCache();
Bitmap bm = tv.getDrawingCache();

LatLng latLng = new LatLng(latitudemy, longitudemy);


BitmapDescriptor icon = BitmapDescriptorFactory.fromBitmap(bm);
BitmapDescriptorFactory.fromResource(R.mipmap.ic_launcher);
map.addMarker(new MarkerOptions().position(new LatLng(latitudemy, longitudemy)).title("origin").snippet("Srivastava").icon(icon));
// Showing the current location in Google Map
map.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("destination").snippet("Srivastava").icon(icon));

答案 3 :(得分:2)

您可能还想尝试开箱即用的群集解决方案:Android Maps Extensions

答案 4 :(得分:0)