title: Google map V2 giving the address of previous touched location
body: <p>I am using Google map v2 in my app. i am placing the marker where i click. when i click again on map the privios marke gone and new marker added. when i check the address then it shows me the address of removed marker. i.e it contains the the last touched location.
  Please help me. How can i remove address as well as marker removed. Here is my code</p>
  
  <pre><code>public class Map extends FragmentActivity {
  GoogleMap gMap;
  static int loginCheck = 0;
  GeoPoint p, currentLocationPixels;
  ConnectionDetector conDec;
  ArrayList&lt;HashMap&lt;String, String&gt;&gt; aList = new ArrayList&lt;HashMap&lt;String, String&gt;&gt;();
  SharedPreferences prefs;
  LatLng latLng;
  MarkerOptions markerOptions;
  EditText desc;
  String addressText = "";
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      setContentView(R.layout.map);
  
      prefs = getApplicationContext().getSharedPreferences("jam",
              MODE_PRIVATE);
  
      conDec = new ConnectionDetector(this);
  
      SupportMapFragment smf = (SupportMapFragment) getSupportFragmentManager()
              .findFragmentById(R.id.mapView);
      gMap = smf.getMap();
  
      gMap.setMyLocationEnabled(true);
      gMap.getUiSettings().setCompassEnabled(true);
      // gMap.setTrafficEnabled(true);
  
  
      gMap.setOnMapClickListener(new OnMapClickListener() {
  
          @Override
          public void onMapClick(LatLng arg0) {
  
              // Getting the Latitude and Longitude of the touched location
              latLng = arg0;
  
              // Clears the previously touched position
              gMap.clear();
              addressText=null;
  
              // Animating to the touched position
              // gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
  
              int caller = getIntent().getIntExtra("button", 0);
              System.out.println(caller);
              switch (caller) {
              case R.id.btMap:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_darkblue)).title(addressText));
                  break;
              case R.id.imageButton1:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_bue)).title(addressText));
                  break;
              case R.id.imageButton2:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_green)).title(addressText));
                  break;
              case R.id.imageButton3:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_light)).title(addressText));
                  break;
              case R.id.imageButton4:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_purple)).title(addressText));
                  break;
              case R.id.imageButton5:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_red)).title(addressText));
                  break;
              case R.id.imageButton6:
                  gMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
                  gMap.addMarker(new MarkerOptions().position(latLng).icon(BitmapDescriptorFactory.fromResource(R.drawable.pin_annotation_yellow)).title(addressText));
                  break;
              }
  
              // Creating a marker
              // markerOptions = new MarkerOptions();
  
              // Setting the position for the marker
              // markerOptions.position(latLng);
  
              // Placing a marker on the touched position
              // gMap.addMarker(markerOptions);
  
              // Adding Marker on the touched location with address
              new ReverseGeocodingTask(getBaseContext()).execute(latLng);
          }
      });
  
      // ** Hide By Gaurav
      // gMap.setOnInfoWindowClickListener(new OnInfoWindowClickListener() {
      // @Override
      // public void onInfoWindowClick(Marker marker) {
      // System.out.println(marker.getPosition().latitude);
      //
      // Intent i = new Intent(Map.this, Detail.class);
      // i.putExtra("lat", "" + marker.getPosition().latitude);
      // i.putExtra("lng", "" + marker.getPosition().longitude);
      // i.putExtra("title", marker.getTitle());
      // i.putExtra("desc", marker.getSnippet());
      // startActivity(i);
      // }
      // });
      getInfo();
  
      CameraPosition cp = new CameraPosition.Builder()
              .target(new LatLng(Double.parseDouble("30.7353"), Double
                      .parseDouble("76.7911"))).zoom(16).build();
      gMap.animateCamera(CameraUpdateFactory.newCameraPosition(cp));
  }
  
  // ** Gaurav Work Start Here
  private class ReverseGeocodingTask extends AsyncTask&lt;LatLng, Void, String&gt; {
      Context mContext;
  
      public ReverseGeocodingTask(Context context) {
          super();
          mContext = context;
      }
  
      // Finding address using reverse geocoding
      @Override
      protected String doInBackground(LatLng... params) {
          Geocoder geocoder = new Geocoder(mContext);
          double latitude = params[0].latitude;
          double longitude = params[0].longitude;
          List&lt;Address&gt; addresses = null;
          //String addressText = "";
          try {
              addresses = geocoder.getFromLocation(latitude, longitude, 1);
          } catch (IOException e) {
              e.printStackTrace();
          }
  
          if (addresses != null &amp;&amp; addresses.size() &gt; 0) {
              Address address = addresses.get(0);
  
              addressText = String.format(
                      "%s, %s, %s",
                      address.getMaxAddressLineIndex() &gt; 0 ? address
                              .getAddressLine(0) : "", address.getLocality(),
                      address.getCountryName());
          }
  
          return addressText;
      }
  
  
      // @Override
      // protected void onPostExecute(String addressText) {
      //
      // // This will be displayed on taping the marker
      // markerOptions.title(addressText);
      //
      // // Placing a marker on the touched position
      // gMap.addMarker(markerOptions);
      //
      // }
  }}
  </code></pre>