Note that there are some explanatory texts on larger screens.

plurals
  1. POandroid googleMaps v2 onMarkerclick comparison
    primarykey
    data
    text
    <p>I have a onMarkerClickListener on my google map which fires when a marker is pressed as it should.</p> <p>the markers are created in a Tag class that creates the marker within itself on a map that is passed though:</p> <p>instance of the list at the start of the map activity:</p> <pre><code>//tags List&lt;Tag&gt; tags = new ArrayList&lt;Tag&gt;(); </code></pre> <p>In the onCreate() of the activity that contains the googleMap I add the markers to a list:</p> <pre><code>public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ....other code here //add the markers to the map tags.add(new Tag(map,1,"City Of Dundee", "Home Of The Jakey", DUNDEE, this.getResources(),R.drawable.ic_launcher)); tags.add(new Tag(map,2,"Some Place","This is some place",LOCATION_Z,this.getResources(),R.drawable.ic_launcher)); ....other code here }//end on create </code></pre> <p>Constructor for the Tag class:</p> <pre><code>public Tag(GoogleMap map, int atagID,String tagTitle, String tagSnippet, LatLng tagPosition, Resources resource, int id){ this.tagID = atagID; this.position = tagPosition; this.title = tagTitle; this.snippet = tagSnippet; this.icon = BitmapDescriptorFactory.fromResource(id); this.theTag = map.addMarker(new MarkerOptions() .position(tagPosition) .title(tagTitle) .snippet(tagSnippet) .icon(icon)); } </code></pre> <p>This creates the tag and it display on the map properly</p> <p>In the listener for the onMarkerClickedListener i compare the marker clicked on the map to the marker from the list but the if statement never passes, even when I compare the titles which are identical.</p> <p>The Listener:</p> <pre><code>onMarkerClickListener = new OnMarkerClickListener(){ @Override public boolean onMarkerClick(Marker marker) { //for loop that goes over array or marker //if marker is equal to mark in array //do marker functionality for(Tag currentTag : tags){ if(currentTag.theTag == marker){ switch(currentTag.tagID){ case 1: //do something for that button Toast.makeText(getApplicationContext(), "marker 1", Toast.LENGTH_SHORT).show(); return true; case 2: Toast.makeText(getApplicationContext(), "marker 2", Toast.LENGTH_SHORT).show(); return false; default: Toast.makeText(getApplicationContext(), "default", Toast.LENGTH_SHORT).show(); return false; } }else{ Toast.makeText(getApplicationContext(), "theTag " + currentTag.tagID + ": " + currentTag.theTag.getTitle(), Toast.LENGTH_SHORT).show(); Toast.makeText(getApplicationContext(), "marker: " + marker.getTitle(), Toast.LENGTH_SHORT).show(); } } return false; } }; </code></pre> <p>I hove no idea why it never reaches the switch statement any ideas?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload