Getting infinite loop on draw() when trying to show a pin on map
<p>I am trying to show a pin on map and trying following code.<br>
And I am not getting the pin on map, but an infinite loop on draw function.
Can anyOne help me plz.</p>

<pre><code>  public class MyMapActivity extends MapActivity 
 {
private MapView mapview; 
MapController mc;
GeoPoint p;
public String strCountry,strAdressLine,strSubAdminArea,strCity,strFeature,strZipcode;
public Vector&lt;UserLocation&gt; userSavedLoaction;

public void garLoacationAddress( double LATITUDE, double LONGITUDE)
{
       String lati=String.valueOf(LATITUDE);
       String longti=String.valueOf(LONGITUDE);
       Geocoder geocoder = new Geocoder(this, Locale.ENGLISH);

       try {
              List&lt;Address&gt; addresses = geocoder.getFromLocation(LATITUDE,LONGITUDE, 1);
              userSavedLoaction=new Vector&lt;UserLocation&gt;();
              UserLocation objUserLocation=new UserLocation();
              if (addresses.size()&gt; 0){
                objUserLocation.Country = addresses.get(0).getCountryName();
                objUserLocation.Address=addresses.get(0).getAddressLine(0);
                objUserLocation.City=addresses.get(0).getLocality();
                objUserLocation.Zip= addresses.get(0).getPostalCode();
                objUserLocation.State=addresses.get(0).getAdminArea();
                objUserLocation.GeoCode=""+LATITUDE+","+LONGITUDE;
                objUserLocation.Is_Primary=false;
                userSavedLoaction.add(objUserLocation);
                Log.i("Location",userSavedLoaction.get(0).Country+userSavedLoaction.get(0).City+userSavedLoaction.get(0).Address+userSavedLoaction.get(0).GeoCode+userSavedLoaction.get(0).State+userSavedLoaction.get(0).Zip);
              }

              else{
                  Log.i("","no adress returned");
                  }
        } 
       catch (IOException e) 
       {
  // TODO Auto-generated catch block
                 e.printStackTrace();

          }             
}

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.map);
    mapview=(MapView)findViewById(R.id.mapView);
    mapview.setSatellite(true);


    mapview.setBuiltInZoomControls(true);
    mc= mapview.getController();

    mc.setZoom(10);

       final MapOverlay mapOverlay = new MapOverlay();           
       List&lt;Overlay&gt; listOfOverlays = mapview.getOverlays();
       listOfOverlays.clear();
       listOfOverlays.add(mapOverlay);        
       mapview.invalidate();


       TabsActivity.btnLogout.setOnClickListener(new OnClickListener()
        {
            @Override
            public void onClick(View v) 
            {


                   Log.i("long"+mapOverlay.LONGITUDE, "lati"+mapOverlay.LATITUDE);
                   garLoacationAddress(mapOverlay.LATITUDE, mapOverlay.LONGITUDE);
                   Ga2ooParsers objGa2ooParsers=new Ga2ooParsers();
                   objGa2ooParsers.addUserSavedLocation(userSavedLoaction);

            }
        });
}
       @Override
       protected boolean isRouteDisplayed()
       {
           return false;
       }
       @Override
       public void onResume()
       {
        super.onResume();
        Log.e("MyMapActivity","onResume");

           TabsActivity.btnBack.setVisibility(View.VISIBLE);
                           TabsActivity.rlCommonTitleBar.setBackgroundResource(R.drawable.top_bar_empty);
           TabsActivity.tvTitle.setText("Map");
           TabsActivity.tvTitle.setVisibility(View.VISIBLE);
           TabsActivity.btnLogout.setBackgroundResource(R.drawable.save);
           TabsActivity.rlCommonTitleBar.invalidate();

           TabsActivity.btnBack.setOnClickListener(new OnClickListener()
           {
            @Override
            public void onClick(View v) 
            {
                MyMapActivity.this.finishFromChild(MyMapActivity.this);
            }
        });


       }

       class MapOverlay extends Overlay
       {

        double LATITUDE;
        double LONGITUDE;
        Geocoder geoCoder = null;



         @Override
            public boolean onTouchEvent(MotionEvent event, MapView mapView) 
            {   
                //---when user lifts his finger---


                if (event.getAction() == 1) {                
                p = mapView.getProjection().fromPixels(
                        (int) event.getX(),
                        (int) event.getY());

                   LATITUDE =   p.getLatitudeE6()/ 1E6;
                   LONGITUDE=   p.getLongitudeE6()/ 1E6;                   
                   Log.i("long"+LONGITUDE, "lati"+LATITUDE);  


        } 
                return false;
            }

         @Override
         public boolean draw(Canvas canvas, MapView mapView, boolean shadow, long when) 
         {

             super.draw(canvas, mapView, shadow);                   
             Geocoder geoCoder = new Geocoder(getApplicationContext(), Locale.getDefault());    
              try {
                  List&lt;Address&gt; addresses = geoCoder.getFromLocationName(
                      "India", 5);

                  if (addresses.size() &gt; 0) {
                      p = new GeoPoint(
                              (int) (addresses.get(0).getLatitude() * 1E6), 
                              (int) (addresses.get(0).getLongitude() * 1E6));
                      Log.i("this is p inside the draw", ""+p);
                  }


                  Point screenPts = new Point();
                  mapView.getProjection().toPixels(p, screenPts);

                  //---add the marker---
                  Bitmap bmp = BitmapFactory.decodeResource(getResources(), R.drawable.red);            
                  canvas.drawBitmap(bmp, screenPts.x, screenPts.y-50, null);  
                  mc.animateTo(p); 
              }
              catch (IOException e) {
                     e.printStackTrace();
                 }
                 return true;

         }
       }
</code></pre>

<p>}</p>
