gpt4 book ai didi

安卓全局定位系统。位置监听器不想获取修复 :(

转载 作者:行者123 更新时间:2023-11-29 02:10:59 25 4
gpt4 key购买 nike

下面是一段代码,用于监听 GPS 更新并向主要 Activity 发送通知

但是它似乎并没有起作用:)

没有错误,只是没有调用 onLocationChanged!

有趣的是:当我运行其他一些应用程序来获取 GPS 定位,然后启动我的应用程序时 => onLocationChanged 被调用,只有精度下降,最终定位丢失。

我还尝试将 GPS 监听器添加到此代码中 => 它有效,每秒都会报告视野中的卫星,但从未获得唯一的修复。

这到底是怎么回事? :)

公共(public)类 PhoneGPSpos{

private Handler myHandler = null;
private LocationManager lm;
private LocationListener locationListener;
private Location currentBest;
Context m_context;

public PhoneGPSpos(Context 上下文, 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;
}

最佳答案

好吧,弄清楚这是一个其他人也看到的问题:显然(至少在某些手机上)如果相机处于 Activity 状态,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 问题

如果有人有解决方案请分享

关于安卓全局定位系统。位置监听器不想获取修复 :(,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7405879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com