简体   繁体   English

android在android的模拟器上获取经纬度

[英]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?嗨,我想在 android 仿真器中检查当前 position 的纬度经度如何实现这一点。

@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.您将在 Eclipse 的 DDMS 透视图中找到此 window。 This way you can test your application with various location values.通过这种方式,您可以使用各种位置值测试您的应用程序。

模拟器控制

go to eclipse DDMS perspective,Via go 到 eclipse DDMS 透视图,通过

Windows>Open Perspective > other > DDMS (You can type to filter the list) Windows>Open Perspective > other > DDMS (你可以输入过滤列表)

find Emulator Control tab找到模拟器控制选项卡

then inside Location Control box然后在位置控制框内

You can send lat, long to emulator to simulate gps changes.您可以将 lat、long 发送到模拟器以模拟 gps 更改。

if you cannot find Emulator Control, just open it via:如果找不到 Emulator Control,只需通过以下方式打开它:

Windows > show view > other > Emulator Control (You can type to filter the list) Windows > 显示视图 > 其他 > 仿真器控制(您可以键入以过滤列表)

You can also using telnet to set the emulator's location您还可以使用 telnet 设置模拟器的位置

  1. open a command shell打开命令 shell

  2. conect to the emulator with the command: telnet localhost使用以下命令连接到模拟器:telnet localhost

  3. to enter a fixed location execute the command:进入固定位置执行命令:

  4. geo fix longitude latitude地理修复经度纬度

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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