finding current location for specific time
<p>i want to find my current location on google map through GPS, but the thing is that it should search current location till a specific amount of time for e.g 30 sec, and after 30 sec GPS should stop searching or GPS should stop automatically.</p>

<p>And then i want to save the current location point as Langitude and Longitude.
My Code is lyk that :-  </p>

<pre><code>//on create

  ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo netInfo = cm.getActiveNetworkInfo();
            if (netInfo != null &amp;&amp; netInfo.isConnected()) {


                lmngr = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
                llstnr = new MyLocationListener();


                 Criteria criteria = new Criteria();
                    provider = lmngr.getBestProvider(criteria, false);
                    Location location = lmngr.getLastKnownLocation(provider);

                    if (location != null) {

                        lmngr.requestLocationUpdates(LocationManager.GPS_PROVIDER,0,0,llstnr);


                      } else {

                          Toast.makeText(getApplicationContext(), "No location found", Toast.LENGTH_LONG).show();
                      }
                //Toast.makeText(getApplicationContext(), "Connection", Toast.LENGTH_LONG).show();  

            }

            else{


                 AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
                 alertDialogBuilder.setTitle("Check Connection");
                 alertDialogBuilder
                .setMessage("No internet Connection Do U Want To Exit ?")
                .setCancelable(false)
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {

                        Nissan_Map_Final.this.finish();
                    }
                  })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

                 AlertDialog alertDialog = alertDialogBuilder.create();

                alertDialog.show();

          //     Toast.makeText(getApplicationContext(), "No Connection", Toast.LENGTH_LONG).show();
            }
</code></pre>

<p>My location listener class :-</p>

<p>public class MyLocationListener implements LocationListener {</p>

<pre><code>    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub

        GeoPoint p = new GeoPoint((int) (location.getLatitude() * 1E6),(int) (location.getLongitude() * 1E6));
        int cur_lati = (int)location.getLatitude();
        int cur_longi = (int)location.getLongitude();   
        float   accuracy = location.getAccuracy();
        String add = " ";

        p = new GeoPoint((int) (cur_lati * 1E6),(int) (cur_longi * 1E6));
        mc = mapView.getController();
        mc.animateTo(p);
        mc.setZoom(18);

        Geocoder geoCoder = new Geocoder(getBaseContext(), Locale.getDefault());
        try {



            List&lt;Address&gt; addresses = geoCoder.getFromLocation(
                    p.getLatitudeE6() / 1E6,
                    p.getLongitudeE6() / 1E6, 1);

            if (addresses.size() &gt; 0)
            {

                for (int i=0; i&lt;addresses.get(0).getMaxAddressLineIndex();i++)
                    add += addresses.get(0).getAddressLine(i) ;

            }

        }
        catch (IOException e) {
            e.printStackTrace();
        }


        cur_loc.setText("Your Accuracy: " + accuracy + "\n" + "Address is:" + location.getLatitude() + "" + location.getLongitude());
    }

    @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
        lmngr.removeUpdates(llstnr);
    }



}
</code></pre>
