这是下面的代码,用于侦听GPS更新并向主要活动发送通知
但是它似乎不起作用:)
没有错误,只有onLocationChanged没有被调用!
有趣的是:当我运行其他应用程序以修复GPS并在启动之后,我的应用程序=> onLocationChanged被调用时,仅准确性下降,最终修复失败。
我还尝试将代码添加到此代码中,GPS侦听器=>可以正常工作,每秒报告一次视野中的卫星,但永远不会对它进行修正。
这到底是怎么回事? :)
公共类PhoneGPSpos {
private Handler myHandler = null;
private LocationManager lm;
private LocationListener locationListener;
private Location currentBest;
Context m_context;
public PhoneGPSpos(Context context,Handler handler){
myHandler = handler;
m_context = context;
lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
// Bundle bundle = new Bundle();
// boolean xtraInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_xtra_injection",bundle);
// boolean timeInjection=lm.sendExtraCommand(LocationManager.GPS_PROVIDER,"force_time_injection",bundle);
currentBest = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
locationListener = new LocationListener()
{
public void onLocationChanged(Location location)
{
Log.w("Compass", "Loc");
if (location != null)
{
currentBest = location;
Message msg = new Message();
msg.arg1 = 5;
myHandler.sendMessage(msg);
}
}
public void onStatusChanged(String provider, int status, Bundle
extras) {
Log.d("Compass", "Stat");
}
public void onProviderEnabled(String provider) {
Log.d("Compass", "Prov e");
}
public void onProviderDisabled(String provider) {
Log.d("Compass", "Prov d");
}
};
}
public void requestGPS()
{
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
Log.d("Compass", "gps requested");
}
public void stopGPS()
{
Log.d("Compass", "gps stopped");
lm.removeUpdates(locationListener);
}
public synchronized Location getBest()
{
return currentBest;
}
}
最佳答案
好的,请弄清楚这也是其他人也看到的一个问题:如果启用了Camera,则显然(至少在某些手机上)GPS监听器的工作效率大大降低。
Problem with getting GPS data when using CameraPreview
Android: Losing GPS signal strength on some phones when I start up the Camera and SurfaceView
Camera Preview and GPS reading in Android
为此http://code.google.com/p/android/issues/detail?id=20098创建了Andorid问题
如果有人有解决方案,请分享
关于android - Android GPS。位置监听器不希望获取修复程序:(,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/7405879/