Reputation: 784
I have added the text to the marker using marker options
TextView text = new TextView(context);
text.setText(" "+assetName+" ");
text.setTextColor(context.getResources().getColor(R.color.color_white));
IconGenerator generator = new IconGenerator(context);
generator.setColor(context.getResources().getColor(R.color.colorAccent));
generator.setContentView(text);
generator.setRotation(360);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromBitmap(icon));
MapFragment.googleMap.addMarker(tp);
Now i want the text "iqbal" on the marker when i click on it.
Upvotes: 1
Views: 281
Reputation: 531
Marker options doesnt have tag attribute. So you have to give the tag feature to the marker
TextView text = new TextView(context);
text.setText("Some Text Here");
text.setTypeface(Typeface.DEFAULT_BOLD);
IconGenerator generator = new IconGenerator(context);
generator.setBackground(context.getDrawable(R.color.cyan_800_overlay));
generator.setContentView(text);
generator.setStyle(IconGenerator.STYLE_BLUE);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions()
.position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(icon));
Marker marker = mMap.addMarker(tp);
marker.setTag(Some Tag Here);
Upvotes: 1
Reputation: 1105
You can't get the text from the marker because your text is inside a generated bitmap. However, you can save the text and anything you can need in the marker tag:
TextView text = new TextView(context);
text.setText(" "+assetName+" ");
text.setTextColor(context.getResources().getColor(R.color.color_white));
IconGenerator generator = new IconGenerator(context);
generator.setColor(context.getResources().getColor(R.color.colorAccent));
generator.setContentView(text);
generator.setRotation(360);
Bitmap icon = generator.makeIcon();
MarkerOptions tp = new MarkerOptions().position(latLng)
.icon(BitmapDescriptorFactory.fromBitmap(icon))
.tag(text);
Marker marker = MapFragment.googleMap.addMarker(tp);
And then
String text = marker.getTag().toString()
Upvotes: 2