Android map with different location with different marker image
<p>I'm doing map application in android.For that,i need to show current location with one marker image.And when i type any address on top editText box,i need to show tht location with different marker image + i can change that second marker into tapped locations.For me,initially it shows current location with one marker well.But when i type.,while second marker has come.,that first marker(current location) will disapper.I want to have both two markers on view.How could i do that?</p>

<p>My code:
Handler h = new Handler() {</p>

<pre><code>    // Invoked by the method onTap()
    // in the class CurrentLocationOverlay
    @Override
    public void handleMessage(Message msg) {
        Bundle data = msg.getData();

        // Getting the Latitude of the location
        int latitude = data.getInt("latitude");

        // Getting the Longitude of the location
        int longitude = data.getInt("longitude");

        // Show the location in the Google Map
        showLocation(latitude, longitude);
    }

};

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Getting reference to map_view available in activity_main.xml
    mapView = (MapView) findViewById(R.id.map_view);

    // Getting reference to tv_location available in activity_main.xml
    tvLocation = (TextView) findViewById(R.id.tv_location);

    initLocationManager();
    // Default Latitude
    int latitude = 28426365;

    // Default Longitude
    int longitude = 77320393;

    // Show the location in the Google Map
    showLocation(latitude, longitude);
}

private void initLocationManager() {
    mapView.setBuiltInZoomControls(true);

    // Getting LocationManager object from System Service LOCATION_SERVICE
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);

    // Creating a criteria object to retrieve provider
    Criteria criteria = new Criteria();

    // Getting the name of the best provider
    String provider = locationManager.getBestProvider(criteria, true);

    // Getting Current Location
    Location location = locationManager.getLastKnownLocation(provider);

    if (location != null) {
        onLocationChanged(location);
    }

    locationManager.requestLocationUpdates(provider, 20000, 0, this);
}

@Override
public void onLocationChanged(Location location) {
    TextView tvLocation = (TextView) findViewById(R.id.tv_location);

    // Getting latitude
    double latitude = location.getLatitude();

    // Getting longitude
    double longitude = location.getLongitude();

    // Setting latitude and longitude in the TextView tv_location
    tvLocation.setText("Latitude:" + latitude + ", Longitude:" + longitude);

    // Creating an instance of GeoPoint corresponding to latitude and
    // longitude
    GeoPoint point = new GeoPoint((int) (latitude * 1E6),
            (int) (longitude * 1E6));

    // Getting MapController
    MapController mapController = mapView.getController();

    // Locating the Geographical point in the Map
    mapController.animateTo(point);

    // Applying a zoom
    mapController.setZoom(15);

    // Redraw the map
    mapView.invalidate();

    // Getting list of overlays available in the map
    List&lt;Overlay&gt; mapOverlays = mapView.getOverlays();

    // Creating a drawable object to represent the image of mark in the map
    Drawable drawable = this.getResources().getDrawable(
            R.drawable.ic_launcher);

    // Creating an instance of ItemizedOverlay to mark the current location
    // in the map
    CurrentLocationOverlay currentLocationOverlay = new CurrentLocationOverlay(
            drawable);

    // Creating an item to represent a mark in the overlay
    OverlayItem currentLocation = new OverlayItem(point,
            "Current Location", "Latitude : " + latitude + ", Longitude:"
                    + longitude);

    // Adding the mark to the overlay
    currentLocationOverlay.addOverlay(currentLocation);

    // Clear Existing overlays in the map
    mapOverlays.clear();

    // Adding new overlay to map overlay
    mapOverlays.add(currentLocationOverlay);

}

@Override
public void onProviderDisabled(String provider) {
    // TODO Auto-generated method stub
}

@Override
public void onProviderEnabled(String provider) {
    // TODO Auto-generated method stub
}

@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
    // TODO Auto-generated method stub
}

private void showLocation(int latitude, int longitude) {

    // Setting Latitude and Longitude in TextView
    tvLocation.setText("Latitude:" + latitude / 1e6 + "," + "Longitude:"
            + longitude / 1e6);

    // Setting Zoom Controls
    mapView.setBuiltInZoomControls(true);

    // Getting the MapController
    MapController mapController = mapView.getController();

    // Getting Overlays of the map
    List&lt;Overlay&gt; overlays = mapView.getOverlays();

    // Getting Drawable object corresponding to a resource image
    Drawable drawable = getResources().getDrawable(R.drawable.marker);

    // Creating an ItemizedOverlay
    TouchedLocationOverlay locationOverlay = new TouchedLocationOverlay(
            drawable, h);

    // Getting the MapController
    MapController mc = mapView.getController();

    // Creating an instance of GeoPoint, to display in Google Map
    GeoPoint p = new GeoPoint(latitude, longitude);

    // Locating the point in the Google Map
    mc.animateTo(p);

    // Creating an OverlayItem to mark the point
    OverlayItem overlayItem = new OverlayItem(p, "Item", "Item");

    // Adding the OverlayItem in the LocationOverlay
    locationOverlay.addOverlay(overlayItem);

    // Clearing the overlays
    overlays.clear();

    // Adding locationOverlay to the overlay
    overlays.add(locationOverlay);

    // Redraws the map
    mapView.invalidate();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return false;
}

private GeoPoint getPoint(double lat, double lon) {
    return (new GeoPoint((int) (lat * 1000000.0), (int) (lon * 1000000.0)));
}

private class SitesOverlay extends ItemizedOverlay&lt;OverlayItem&gt; {
    private List&lt;OverlayItem&gt; items = new ArrayList&lt;OverlayItem&gt;();

    public SitesOverlay(Drawable marker, double lat, double lang) {
        super(marker);

        boundCenterBottom(marker);

        items.add(new OverlayItem(getPoint(lat, lang), "", ""));

        populate();
    }

    public SitesOverlay(Drawable marker, double[] latitude,
            double[] longitude) {
        super(marker);

        // boundCenterBottom(marker);

        for (int i = 0; i &lt; latitude.length; i++) {
            items.add(new OverlayItem(getPoint(latitude[i], longitude[i]),
                    "", ""));
        }

        populate();
    }

    @Override
    protected OverlayItem createItem(int i) {
        return (items.get(i));
    }

    @Override
    protected boolean onTap(int i) {
        /*
         * Toast.makeText(LocationBasedServicesV2.this,
         * items.get(i).getSnippet(), Toast.LENGTH_SHORT).show();
         */

        return (true);
    }

    @Override
    public int size() {
        return (items.size());
    }
}

@Override
protected boolean isRouteDisplayed() {
    // TODO Auto-generated method stub
    return false;
}
</code></pre>

<p>TochedLocation:</p>

<pre><code>private ArrayList&lt;OverlayItem&gt; mOverlays = new ArrayList&lt;OverlayItem&gt;();    
private Handler handler;

public TouchedLocationOverlay(Drawable defaultMarker,Handler h) {
    super(boundCenterBottom(defaultMarker));    

    // Handler object instantiated in the class MainActivity
    this.handler = h;
}

// Executed, when populate() method is called
@Override
protected OverlayItem createItem(int arg0) {
    return mOverlays.get(arg0);     
}   

@Override
public int size() {     
    return mOverlays.size();
}   

public void addOverlay(OverlayItem overlay){
    mOverlays.add(overlay);
    populate(); // Invokes the method createItem()
}

// This method is invoked, when user tap on the map
@Override
public boolean onTap(GeoPoint p, MapView map) {     

    List&lt;Overlay&gt; overlays = map.getOverlays();

    // Creating a Message object to send to Handler
    Message message = new Message();

    // Creating a Bundle object ot set in Message object
    Bundle data = new Bundle();

    // Setting latitude in Bundle object
    data.putInt("latitude", p.getLatitudeE6());

    // Setting longitude in the Bundle object
    data.putInt("longitude", p.getLongitudeE6());

    // Setting the Bundle object in the Message object
    message.setData(data);

    // Sending Message object to handler
    handler.sendMessage(message);       

    return super.onTap(p, map);
}   
</code></pre>

<p>Thanks.</p>
