SRam
SRam

Reputation: 2828

android get latitude and longitude on emulator of android

hi iwant to check lat long of current position in android emulator how to achive this..??it is possible to get current position latitude and longitude on emulator???if yes then what setting is required in emulator?

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

    LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    LocationListener ll = new Mylocationlistener();

    boolean isGPS = lm
            .isProviderEnabled(LocationManager.GPS_PROVIDER);

    // If GPS is not enable then it will be on
    if(!isGPS)
    {
        Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
        intent.putExtra("enabled", true);
         sendBroadcast(intent);


    }

    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, ll);
}
private class Mylocationlistener implements LocationListener {
    @Override
    public void onLocationChanged(Location location) {
        if (location != null) {
            Log.d("LOCATION CHANGED", location.getLatitude() + "");
            Log.d("LOCATION CHANGED", location.getLongitude() + "");
            float speed = location.getSpeed();
            double altitude = location.getAltitude();
            Toast.makeText(currentlatlong.this,"Latitude = "+
                    location.getLatitude() + "" +"Longitude = "+ location.getLongitude()+"Altitude = "+altitude+"Speed = "+speed,
                    Toast.LENGTH_LONG).show();
        }
    }

    @Override
    public void onProviderDisabled(String provider) {
    }

    @Override
    public void onProviderEnabled(String provider) {
    }

    @Override
    public void onStatusChanged(String provider, int status, Bundle extras) {
    }
}

Upvotes: 3

Views: 7056

Answers (3)

Michael
Michael

Reputation: 3739

You can also using telnet to set the emulator's location

  1. open a command shell

  2. conect to the emulator with the command: telnet localhost

  3. to enter a fixed location execute the command:

  4. geo fix longitude latitude

Upvotes: 1

Adil Soomro
Adil Soomro

Reputation: 37729

go to eclipse DDMS perspective,Via

Windows>Open Perspective > other > DDMS (You can type to filter the list)

find Emulator Control tab

then inside Location Control box

You can send lat, long to emulator to simulate gps changes.

if you cannot find Emulator Control, just open it via:

Windows > show view > other > Emulator Control (You can type to filter the list)

Upvotes: 3

Gabriel Negut
Gabriel Negut

Reputation: 13960

You'll find this window in the DDMS perspective in Eclipse. This way you can test your application with various location values.

Emulator Control

Upvotes: 6

Related Questions