From abc8d0aaefb7aa6fd8ea7068645e0a0abe45026b Mon Sep 17 00:00:00 2001 From: Stephen McDonald Date: Tue, 19 Jul 2016 12:00:03 +1000 Subject: [PATCH] Add marker data demo Change-Id: Ib8c558fe5165b49e30f33d8f2b18093ddbc4b370 --- .../example/mapdemo/MarkerDemoActivity.java | 23 +++++++++++++++++-- .../app/src/main/res/layout/marker_demo.xml | 5 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java b/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java index dd09b28d..555e3892 100644 --- a/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java +++ b/ApiDemos/app/src/main/java/com/example/mapdemo/MarkerDemoActivity.java @@ -179,6 +179,8 @@ public class MarkerDemoActivity extends AppCompatActivity implements private TextView mTopText; + private TextView mTagText; + private SeekBar mRotationBar; private CheckBox mFlatBox; @@ -193,6 +195,7 @@ public class MarkerDemoActivity extends AppCompatActivity implements setContentView(R.layout.marker_demo); mTopText = (TextView) findViewById(R.id.top_text); + mTagText = (TextView) findViewById(R.id.tag_text); mRotationBar = (SeekBar) findViewById(R.id.rotationSeekBar); mRotationBar.setMax(360); @@ -308,14 +311,16 @@ public class MarkerDemoActivity extends AppCompatActivity implements int numMarkersInRainbow = 12; for (int i = 0; i < numMarkersInRainbow; i++) { - mMarkerRainbow.add(mMap.addMarker(new MarkerOptions() + Marker marker = mMap.addMarker(new MarkerOptions() .position(new LatLng( -30 + 10 * Math.sin(i * Math.PI / (numMarkersInRainbow - 1)), 135 - 10 * Math.cos(i * Math.PI / (numMarkersInRainbow - 1)))) .title("Marker " + i) .icon(BitmapDescriptorFactory.defaultMarker(i * 360 / numMarkersInRainbow)) .flat(flat) - .rotation(rotation))); + .rotation(rotation)); + marker.setTag(0); + mMarkerRainbow.add(marker); } } @@ -417,6 +422,20 @@ public class MarkerDemoActivity extends AppCompatActivity implements Toast.makeText(this, marker.getTitle() + " z-index set to " + zIndex, Toast.LENGTH_SHORT).show(); + // Markers can store and retrieve a data object via the getTag/setTag methods. + // Here we use it to retrieve the number of clicks stored for this marker. + Integer clickCount = (Integer) marker.getTag(); + // Check if a click count was set. + if (clickCount != null) { + clickCount = clickCount + 1; + // Markers can store and retrieve a data object via the getTag/setTag methods. + // Here we use it to store the number of clicks for this marker. + marker.setTag(clickCount); + mTagText.setText(marker.getTitle() + " has been clicked " + clickCount + " times."); + } else { + mTagText.setText(""); + } + mLastSelectedMarker = marker; // We return false to indicate that we have not consumed the event and that we wish // for the default behavior to occur (which is for the camera to move such that the diff --git a/ApiDemos/app/src/main/res/layout/marker_demo.xml b/ApiDemos/app/src/main/res/layout/marker_demo.xml index 66fd8bb8..1e915320 100644 --- a/ApiDemos/app/src/main/res/layout/marker_demo.xml +++ b/ApiDemos/app/src/main/res/layout/marker_demo.xml @@ -25,6 +25,11 @@ android:lines="2" android:text="@string/drag_melbourne" /> + +