简体   繁体   中英

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) {
    }
}

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

模拟器控制

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)

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM