@@ -179,6 +179,8 @@ private void render(Marker marker, View view) {
179
179
180
180
private TextView mTopText ;
181
181
182
+ private TextView mTagText ;
183
+
182
184
private SeekBar mRotationBar ;
183
185
184
186
private CheckBox mFlatBox ;
@@ -193,6 +195,7 @@ protected void onCreate(Bundle savedInstanceState) {
193
195
setContentView (R .layout .marker_demo );
194
196
195
197
mTopText = (TextView ) findViewById (R .id .top_text );
198
+ mTagText = (TextView ) findViewById (R .id .tag_text );
196
199
197
200
mRotationBar = (SeekBar ) findViewById (R .id .rotationSeekBar );
198
201
mRotationBar .setMax (360 );
@@ -308,14 +311,16 @@ private void addMarkersToMap() {
308
311
309
312
int numMarkersInRainbow = 12 ;
310
313
for (int i = 0 ; i < numMarkersInRainbow ; i ++) {
311
- mMarkerRainbow . add ( mMap .addMarker (new MarkerOptions ()
314
+ Marker marker = mMap .addMarker (new MarkerOptions ()
312
315
.position (new LatLng (
313
316
-30 + 10 * Math .sin (i * Math .PI / (numMarkersInRainbow - 1 )),
314
317
135 - 10 * Math .cos (i * Math .PI / (numMarkersInRainbow - 1 ))))
315
318
.title ("Marker " + i )
316
319
.icon (BitmapDescriptorFactory .defaultMarker (i * 360 / numMarkersInRainbow ))
317
320
.flat (flat )
318
- .rotation (rotation )));
321
+ .rotation (rotation ));
322
+ marker .setTag (0 );
323
+ mMarkerRainbow .add (marker );
319
324
}
320
325
}
321
326
@@ -417,6 +422,20 @@ public void run() {
417
422
Toast .makeText (this , marker .getTitle () + " z-index set to " + zIndex ,
418
423
Toast .LENGTH_SHORT ).show ();
419
424
425
+ // Markers can store and retrieve a data object via the getTag/setTag methods.
426
+ // Here we use it to retrieve the number of clicks stored for this marker.
427
+ Integer clickCount = (Integer ) marker .getTag ();
428
+ // Check if a click count was set.
429
+ if (clickCount != null ) {
430
+ clickCount = clickCount + 1 ;
431
+ // Markers can store and retrieve a data object via the getTag/setTag methods.
432
+ // Here we use it to store the number of clicks for this marker.
433
+ marker .setTag (clickCount );
434
+ mTagText .setText (marker .getTitle () + " has been clicked " + clickCount + " times." );
435
+ } else {
436
+ mTagText .setText ("" );
437
+ }
438
+
420
439
mLastSelectedMarker = marker ;
421
440
// We return false to indicate that we have not consumed the event and that we wish
422
441
// for the default behavior to occur (which is for the camera to move such that the
0 commit comments