Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Add a cache to your <code>InfoWindowAdapter</code> code and modify its <code>getInfoContents()</code> method to check it:</p> <pre><code> googleMap.setInfoWindowAdapter(new InfoWindowAdapter() { LruCache&lt;Marker, View&gt; cache = new LruCache&lt;Marker, View&gt;(8); // added // no change to getInfoWindow() @SuppressWarnings("unchecked") @Override public View getInfoContents(Marker marker) { View v = cache.get(marker); if (v == null) { LayoutInflater inflater = (LayoutInflater) MapsDemo.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); v = inflater.inflate(R.layout.custom_info, null); new LocateGeopoint(v, marker).execute(marker.getPosition()); cache.put(marker, v); } return v; } }); </code></pre> <p>Adjust the code in your <code>LocateGeopoint</code> class, adding a reference to the <code>Marker</code> and calling <code>showInfoWindow()</code> after updating your TextView.</p> <pre><code>public class LocateGeopoint extends AsyncTask&lt;LatLng, String, List&lt;Address&gt;&gt; { // : Marker marker; // added public LocateGeopoint(View v, Marker marker) { // : this.marker = marker; // added } @Override protected void onPostExecute(List&lt;Address&gt; addresses) { super.onPostExecute(addresses); if(addresses!=null){ // : tv.setText(city); marker.showInfoWindow(); // added } } // no change to doInBackground() } </code></pre> <p>NOTE: This answer is really just a quick and dirty implementation (I haven't really tested it, but I think it should work) based on the answer from MaciejGórski on this question, please read the referenced post in that answer for more details :)</p>
 

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