Skip to content

Commit abc8d0a

Browse files
committed
Add marker data demo
Change-Id: Ib8c558fe5165b49e30f33d8f2b18093ddbc4b370
1 parent d4b2a1e commit abc8d0a

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,8 @@ private void render(Marker marker, View view) {
179179

180180
private TextView mTopText;
181181

182+
private TextView mTagText;
183+
182184
private SeekBar mRotationBar;
183185

184186
private CheckBox mFlatBox;
@@ -193,6 +195,7 @@ protected void onCreate(Bundle savedInstanceState) {
193195
setContentView(R.layout.marker_demo);
194196

195197
mTopText = (TextView) findViewById(R.id.top_text);
198+
mTagText = (TextView) findViewById(R.id.tag_text);
196199

197200
mRotationBar = (SeekBar) findViewById(R.id.rotationSeekBar);
198201
mRotationBar.setMax(360);
@@ -308,14 +311,16 @@ private void addMarkersToMap() {
308311

309312
int numMarkersInRainbow = 12;
310313
for (int i = 0; i < numMarkersInRainbow; i++) {
311-
mMarkerRainbow.add(mMap.addMarker(new MarkerOptions()
314+
Marker marker = mMap.addMarker(new MarkerOptions()
312315
.position(new LatLng(
313316
-30 + 10 * Math.sin(i * Math.PI / (numMarkersInRainbow - 1)),
314317
135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1))))
315318
.title("Marker " + i)
316319
.icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow))
317320
.flat(flat)
318-
.rotation(rotation)));
321+
.rotation(rotation));
322+
marker.setTag(0);
323+
mMarkerRainbow.add(marker);
319324
}
320325
}
321326

@@ -417,6 +422,20 @@ public void run() {
417422
Toast.makeText(this, marker.getTitle() + " z-index set to " + zIndex,
418423
Toast.LENGTH_SHORT).show();
419424

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+
420439
mLastSelectedMarker = marker;
421440
// We return false to indicate that we have not consumed the event and that we wish
422441
// for the default behavior to occur (which is for the camera to move such that the

ApiDemos/app/src/main/res/layout/marker_demo.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@
2525
android:lines="2"
2626
android:text="@string/drag_melbourne" />
2727

28+
<TextView
29+
android:id="@+id/tag_text"
30+
android:layout_width="match_parent"
31+
android:layout_height="wrap_content" />
32+
2833
<LinearLayout
2934
android:layout_width="match_parent"
3035
android:layout_height="wrap_content">

0 commit comments

Comments
 (0)