Android get latitude and longitude on android emulator

hi to check lat long current position in android emulator, how to achieve this .. ?? can I get the current latitude and longitude on the emulator ??? If so, what setting is required in the 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) {
    }
}
+3
source share
3 answers

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

Emulator control

+6
source

go to eclipse perspectives DDMS, Via

Windows> Open Perspective> other> DDMS (you can print a list for filtering)

find the tab "Emulator Management"

then inside the location control unit

lat, , gps.

, :

Windows > show view > other > Emulator Control ( , )

+3

You can also use telnet to set the emulator location.

  • open command shell

  • interact with the emulator using the command: telnet localhost

  • to enter a fixed location, run the command:

  • geo fix longitude latitude

+1
source

All Articles