[英]android get latitude and longitude on emulator of android
嗨,我想在 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) {
}
}
您将在 Eclipse 的 DDMS 透视图中找到此 window。 通过这种方式,您可以使用各种位置值测试您的应用程序。
go 到 eclipse DDMS 透视图,通过
Windows>Open Perspective > other > DDMS (你可以输入过滤列表)
找到模拟器控制选项卡
然后在位置控制框内
您可以将 lat、long 发送到模拟器以模拟 gps 更改。
如果找不到 Emulator Control,只需通过以下方式打开它:
Windows > 显示视图 > 其他 > 仿真器控制(您可以键入以过滤列表)
您还可以使用 telnet 设置模拟器的位置
打开命令 shell
使用以下命令连接到模拟器:telnet localhost
进入固定位置执行命令:
地理修复经度纬度
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.