title: marker id changes when set tag instance
body: <p>I am working with google maps and markers to display some information about location where picture was taking and other info about that.</p>
  
  <p>So basicly i have a activity where i have a list of photos that are related to a specific plant and inside that activity i have a option to see it on map. When i press on that option all of the photos(that has a location) are displayed as gree markers on the map, the currentPhoto clicked is displayed as a yellow marker.</p>
  
  <p>So when i click on the "see on map" i pass the array of all my photos, the selected photo id, and the current location of the user.</p>
  
  <p><strong>Like this:</strong></p>
  
  <pre><code> public void showMap(View view){
          Intent i = new Intent(this,MapsActivity.class);
          i.putExtra("currentLat",location.getLatitude());
          i.putExtra("currentLon",location.getLongitude());
          i.putExtra("positionCurr",pos);
          Bundle bundle = new Bundle();
          bundle.putSerializable("key", photos);
          i.putExtras(bundle);
          startActivity(i);
      }
  </code></pre>
  
  <p><strong>then on the map activity i initialize them like this:</strong></p>
  
  <pre><code>public void onMapReady(GoogleMap googleMap) {
          mMap = googleMap;
          Marker marker;
          LatLng currentZone = null;
          LatLng plantLocation = null;
          LatLng photosLocation = null;
          positions = new ArrayList&lt;&gt;();
  
  
          allPhotos = (LinearLayout)findViewById(R.id.allFotos);
          specificPhoto = (LinearLayout)findViewById(R.id.Photo);
          myPos = (LinearLayout)findViewById(R.id.myPos);
          Double currentLat = getIntent().getDoubleExtra("currentLat", 0);
          Double currentLon = getIntent().getDoubleExtra("currentLon", 0);
          int currentPlantId = getIntent().getIntExtra("positionCurr",-1);
  
          allPhotos.setOnClickListener(new View.OnClickListener() {
              int count = 0;
              @Override
              public void onClick(View v) {
                  LatLng plantPos = new LatLng(positions.get(count).latitude,positions.get(count).longitude);
                  count++;
                  if(count == positions.size() - 1){
                      count = 0;
                  }
                  mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(plantPos, 35));
              }
          });
  
          Intent intent = this.getIntent();
          Bundle bundle = intent.getExtras();
  
          final ArrayList&lt;Photo&gt; photos = (ArrayList&lt;Photo&gt;) bundle.getSerializable("key");
          Log.d("photos",String.valueOf(photos.size()));
  
          if (currentLat != null &amp;&amp; currentLon != null &amp;&amp; currentLat != 0 &amp;&amp; currentLon != 0) {
              currentZone = new LatLng(currentLat, currentLon);
              mMap.addMarker(new MarkerOptions().position(currentZone).title("Marker in Portugal"));
              mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(currentZone, 15));
              found = true;
          }
  
          BitmapDescriptor bitmapDescriptor;
  
          LatLng latLng;
          int positionSave = -1;
          int index = 0;
  
  
          for (final Photo p : photos) {
              if (p.getLat() != null &amp;&amp; p.getLon() != null) // check for 0.0
              {
                  if(p.getId() == currentPlantId ){
                      bitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW);
                      plantLocation = new LatLng(p.getLat(),p.getLon());
                      mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(plantLocation, 35f));
                      found = true;
                      mMap.addMarker(new MarkerOptions().position(plantLocation)
                              .icon(bitmapDescriptor))
                              .setTag(p);
                  }
                  else{
                      bitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN);
                      plantLocation = new LatLng(p.getLat(),p.getLon());
                      positions.add(plantLocation);
                      positionSave = index;
                      mMap.addMarker(new MarkerOptions().position(plantLocation)
                              .icon(bitmapDescriptor))
                              .setTag(p);
                  }
                      photosLocation = new LatLng(p.getLat(), p.getLon());
  
  
              }
              index++;
          }
  </code></pre>
  
  <p>when i click on the marker the problem is displayed, sometimes i don't get the right id of the clicked photo, and i can see it with the yellow marker, the yellow marker represent the photo that i has selected in the previous activity, when i click on the yellow marker on the map the photo is diferent.</p>
  
  <p>I already checked the passed id and it is correct, i tried to debug and everything seems fine when i set the tag, but when i receive the id is just wrong, i don't know what is really going on, is it because i can't pass a instance to the marker tag? or am i pointing to the same object? need some help with this.</p>
  
  <p><strong>Here is the onClick for the marker:</strong></p>
  
  <pre><code>mMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
  
    @Override
          public boolean onMarkerClick(Marker marker) {
              Photo photo = new Photo();
              Boolean exist = false;
              List &lt;Address&gt; address = new ArrayList&lt;Address&gt;();
                 photo = (Photo)marker.getTag();
              Log.d("ph123",String.valueOf(photo.getId()));
  
              AlertDialog.Builder builder = new AlertDialog.Builder(MapsActivity.this);
  
              final AlertDialog dialog = builder.create();
              dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
  
              LayoutInflater inflater = MapsActivity.this.getLayoutInflater();
              View view = inflater.inflate(R.layout.custom_dialog,null);
              ImageView image = (ImageView)view.findViewById(R.id.imageView1);
              image.setScaleType(ImageView.ScaleType.FIT_XY);
              TextView countryTxt = (TextView)view.findViewById(R.id.country);
              TextView cityTxt = (TextView)view.findViewById(R.id.city);
              TextView streetTxt = (TextView)view.findViewById(R.id.street);
              String street = null;
              String city = null;
              String country = null;
              try {
                  Geocoder geocoder;
                  geocoder = new Geocoder(MapsActivity.this, Locale.getDefault());
  
                  address = geocoder.getFromLocation(photo.getLat(),photo.getLon(), 1); // Here 1 represent max location result to returned, by documents it recommended 1 to 5
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              if(address != null &amp;&amp; address.size() &gt; 0){
                  street = address.get(0).getAddressLine(0); // If any additional address line present than only, check with max available address lines by getMaxAddressLineIndex()
                  city = getCity(address);
  
                  if(street == null) {
                      street = address.get(0).getThoroughfare();
                  }
                  country = address.get(0).getCountryName();
              }
  
  
              if(street == null){
                  street = "desconhecido";
              }
  
              if(country == null){
                  country = "desconhecido";
              }
  
              countryTxt.setText(country);
              cityTxt.setText(city);
              streetTxt.setText(street);
  
              loadPhoto(photo.getPath(),image);
              dialog.setView(view);
              //searching marker id in locationDetailses and getting all the information of a particular marker
  
  
              // Create the AlertDialog
              //AlertDialog dialog = builder.create();
              dialog.show();
  
  
              // Add the button
  
  
  
          return false;
      }
  });
  </code></pre>
  
  <p>}</p>
  
  <p><strong>important part of the marker code:</strong></p>
  
  <pre><code>Photo photo = new Photo();
  photo = (Photo)marker.getTag();
  Log.d("ph123",String.valueOf(photo.getId())); // wrong id here
  </code></pre>
  
  <p>Any help would be appreciate,</p>
  
  <p>Thanks!</p>