13

My goal is to have multiple markers with text on each on the Android Google Maps API v2 map. The info windows approach (showInfoWindow()) is not suitable, because only one info window is displayed at a time. For example I want to have something like this: enter image description here

As you can see each marker has its own data (number for this example) displayed all the time. How can I achieve this with Android Google Maps API v2?

Paulius
  • 242
  • 1
  • 4
  • 12

5 Answers5

10

to do that you'll have to customize the icon of each individual marker to be what you need. Here's the link: https://developers.google.com/maps/documentation/android/marker#customize_a_marker

Then you can put some PNG resources (a blue, a yellow and a red), and at runtime get correct Bitmap, write the text on the bitmap by code, and then set as the custom-marker with the fromBitmap (Bitmap image) method.

Budius
  • 38,680
  • 16
  • 97
  • 139
6

Try these Link It is best to use & It will help to how to Add Multiple markers with text on Android Google Maps API v2

  1. Link1
  2. Link2
Community
  • 1
  • 1
Dixit Patel
  • 6,179
  • 1
  • 31
  • 42
3

try out this

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));
Will
  • 13,998
  • 1
  • 40
  • 43
Shikhar
  • 303
  • 1
  • 16
2

You may also want to try out-of-the-box solution for clustering: Android Maps Extensions

MaciejGórski
  • 22,050
  • 7
  • 68
  • 93
0

As an update:
android maps utils now has a Marker Clustering Utility
https://developers.google.com/maps/documentation/android/utility/marker-clustering

https://github.com/googlemaps/android-maps-utils

Paul Alexander
  • 2,546
  • 3
  • 29
  • 67