您好我想檢查在Android模擬器當前位置的緯度經度如何實現這個.. ??有可能得到當前位置的經緯度在仿真器???如果是的話模擬器需要什麼設置?android獲取緯度和經度的模擬器的android
@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) {
}
}
只能定義模擬地點,模擬器本身無法獲得GPS數據... – WarrenFaith 2011-06-07 11:28:06
@ WarrenFaith謝謝你回答..means android devise是測試當前位置lat long所必需的。 – SRam 2011-06-07 11:31:26
您可以使用模擬位置來測試您的代碼是否有效。對於真實數據的測試,您需要有一個設備,並且需要運行:) – WarrenFaith 2011-06-07 11:32:56