0

I am developed a GPS application for getting Latitude and Longitude, by using Emulator Control manual sending Latitude & Longitude. That works perfectly.

But i need Latitude and Longitude without using Emulator Control. Is it posssible?

If any body know please help me & if possible give me a code for that.

//Here is my code..

public class GPSLocationActivity extends Activity {
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 1; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 1000; // in Milliseconds

protected LocationManager locationManager;

protected Button retrieveLocationButton;
protected TextView txt;

@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    txt = (TextView)findViewById(R.id.tv);

    retrieveLocationButton = (Button) findViewById(R.id.retrieve_location_button);

    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

    locationManager.requestLocationUpdates(
            LocationManager.GPS_PROVIDER, 
            MINIMUM_TIME_BETWEEN_UPDATES, 
            MINIMUM_DISTANCE_CHANGE_FOR_UPDATES,
            new MyLocationListener()
    );

    retrieveLocationButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            showCurrentLocation();
        }
    });        

}    

protected void showCurrentLocation() {

    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

    if (location != null) {
        String message = String.format(
                "Current Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(GPSLocationActivity.this, message,
                Toast.LENGTH_LONG).show();
        txt.setText(message);

    }

}   

private class MyLocationListener implements LocationListener {

    public void onLocationChanged(Location location) {
        String message = String.format(
                "New Location \n Longitude: %1$s \n Latitude: %2$s",
                location.getLongitude(), location.getLatitude()
        );
        Toast.makeText(GPSLocationActivity.this, message, Toast.LENGTH_LONG).show();
    }

    public void onStatusChanged(String s, int i, Bundle b) {
        Toast.makeText(GPSLocationActivity.this, "Provider status changed",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderDisabled(String s) {
        Toast.makeText(GPSLocationActivity.this,
                "Provider disabled by the user. GPS turned off",
                Toast.LENGTH_LONG).show();
    }

    public void onProviderEnabled(String s) {
        Toast.makeText(GPSLocationActivity.this,
                "Provider enabled by the user. GPS turned on",
                Toast.LENGTH_LONG).show();
    }

}

}

//Out Put click emulator

Cœur
  • 37,241
  • 25
  • 195
  • 267
  • your code seems ok, if you are not sending lat/long manually on the emulator control, then you have to use a device with GPS enabled to get lat and long with location manager – Habib Mar 27 '12 at 06:20
  • possible duplicate of [How do I get the current GPS location programmatically in Android?](http://stackoverflow.com/questions/1513485/how-do-i-get-the-current-gps-location-programmatically-in-android) – Samir Mangroliya Mar 27 '12 at 06:23
  • I enable the "Use GPS Satelite" in emulator with click the check box.. –  Mar 27 '12 at 06:28
  • I enable the "Use GPS Satelite" in emulator with click the check box. –  Mar 27 '12 at 06:30
  • here is my emulator with enable GPS. http://dl.dropbox.com/u/58701258/GPS_LOC.png –  Mar 27 '12 at 06:34

1 Answers1

0

But i need Latitude and Longitude without using Emulator Control

AFAIK not possible, Cause The EMULATOR has no Physical GPS System like a Device. So you must have to pass a dummy lat-long position to it.

MKJParekh
  • 34,073
  • 11
  • 87
  • 98