我正在编写一个Android应用程序来获取我的设备的位置,它总是显示GPS状态为TEMPORARILY UN AVAILABLE,它甚至没有调用Location Changed方法,即使我正在改变我的手机的位置,请你看看以下代码的问题
ls= (ArrayList<String>)lm.getProviders(false);
Log.e(""," SIZE "+ls.size());
sb=new StringBuilder();
for(int i=0;i<ls.size();i++)
{Log.e("","Data : "+ls.get(i));
lp=lm.getProvider(ls.get(i));
sb.append("\nProvider Name : "+lp.getName());
sb.append("\nPower Requirement :"+lp.getPowerRequirement());
sb.append("\nAccuracy : "+lp.getAccuracy()+"\n\n");
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1, 1, this);
Location location=lm.getLastKnownLocation(ls.get(i));
}
strt.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv=(TextView)findViewById(R.id.TextView01);
tv.setText("StarteD :"+sb);
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
TextView tv=(TextView)findViewById(R.id.TextView01);
tv.setText("STOPPED ys :"+res);
Location location=lm.getLastKnownLocation(ls.get(1));
if(location==null)
Log.e("","location object null");
try{
tv.append("\nLogitude: "+location.getLongitude());
tv.append("\nLattitude: "+location.getLatitude());
tv.append("\nTime:"+location.getTime());
tv.append("\nSpeed: "+location.getSpeed());
tv.append("\n Provider:"+location.getProvider());
}catch(Exception e){}
}
});
}
@Override
public void onLocationChanged(Location location) {
Log.e("","LocationChandgeD... ");
}
@Override
public void onProviderDisabled(String provider) {
Log.e("",provider+" DIsabled... ");
}
@Override
public void onProviderEnabled(String provider) {
Log.e("",provider+" Enabled... ");
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
switch (status) {
case LocationProvider.OUT_OF_SERVICE:
Toast.makeText(this, "Status Changed: Out of Service",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.TEMPORARILY_UNAVAILABLE:
Toast.makeText(this, "Status Changed: Temporarily Unavailable",
Toast.LENGTH_SHORT).show();
break;
case LocationProvider.AVAILABLE:
Log.e("", "Status Changed: Available");
Toast.makeText(this, "Status Changed: Available",
Toast.LENGTH_SHORT).show();
break;
}
}
答案 0 :(得分:0)
如果没有清晰的天空视野(室内或密集的针叶树覆盖范围内),GPS无法正常工作。也许你应该尝试去户外测试你的程序。