Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid GoogleMaps V2 maker object reference lost
    primarykey
    data
    text
    <p>I´m developing an app that uses Google Maps V2. When the map fragment it´s loaded and the markers are painted, I´ve got a button on the action bar that calls another activity for results that will act as a place finder.</p> <p>On this activity result, I search on my <code>mMarkers</code> which is a <code>HashMap&lt;Long, Marker&gt;</code> like this:</p> <pre><code>if (mMarkers.containsKey(place.id)) { mMarkers.get(place.id).showInfoWindow(); mMap.animateCamera(CameraUpdateFactory.newCameraPosition(updateCamera(new LatLng(place.lat, place.lng)))); } else { Marker marker = mMap.addMarker( new MarkerOptions() .position(markerPos) .title(place.name) ); marker.showInfoWindow(); mMarkers.put(place.id, marker); // if it´s not on the map I put it mMap.animateCamera(CameraUpdateFactory.newCameraPosition(updateCamera(new LatLng(place.lat, place.lng)))); } </code></pre> <p>I show the markers infoWindow because I´ve got a <code>onInfoWindowClick</code> implemented.</p> <p>Here comes the main problem. This is my <code>onInfoWindowClick</code> event:</p> <pre><code>@Override public void onInfoWindowClick(Marker marker) { Long placeId = null; if (mMarkers.containsValue(marker)) { Iterator&lt;Entry&lt;Long, Marker&gt;&gt; it = mMarkers.entrySet().iterator(); while (it.hasNext()) { Map.Entry&lt;Long, Marker&gt; pairs = (Map.Entry&lt;Long, Marker&gt;)it.next(); if (pairs.getValue().getId().equals(marker.getId())) { placeId = pairs.getKey(); } } if (placeId != null) { Intent intent = new Intent(mContext, PlaceActivity.class); intent.putExtra("placeId", placeId); startActivity(intent); } } } </code></pre> <p>When I check the <code>mMarkers.containsValue(marker)</code> the reference to the marker object it´s different from the one I´ve got on the same map on the above <code>onActivityResult</code> function.</p> <p>I´m not creating any new instance of that marker object so I don't really understand why it changes that reference.</p> <p><em><strong>--- UPDATE ---</em></strong></p> <p>I´ve tried without showing the infoWindow and it works perfect. Any ideas why this happens or any workaround to this?</p> <p>Lots of thanks in regard!!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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