Android的全球定位系统。位置监听器并不想获得一个修复:( [英] Android GPS. Location Listener does not want to acquire a fix :(

查看:345
本文介绍了Android的全球定位系统。位置监听器并不想获得一个修复:(的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是低于一个code假设监听GPS更新和发送通知的主要活动

Here is a code below that suppose to listen for GPS updates and send notifications to main activity

但它似乎并不奏效:)

没有错误,仅onLocationChanged不叫!

No errors, only onLocationChanged is not called!

有趣的是:当我运行其他应用获取GPS定位,之后开始我的应用程序=> onLocationChanged被调用,只是精度降解,最终弄不好会丢失

Funny thing is: when I run some other app to get GPS fix and after that start my app => onLocationChanged gets called, only accuracy is degrading, and eventually fix is lost.

我也试图添加到此code GPS监听器=>它的工作原理,针对卫星的报道得到了每秒,唯一的解决方法是从来没有accuired。

I also tried to add to this code GPS listener=> it works, satellites in view got reported every second, only fix is never accuired.

这到底是怎么回事? :)

What the hell is going on? :)

公共类PhoneGPSpos {

public class PhoneGPSpos{

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

公共PhoneGPSpos(上下文的背景下,处理程序处理){

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;
}

}

推荐答案

好吧,搞清楚这是也被其他人看到的一个问题:显然是(至少在某些手机上),GPS监听工作,如果相机是非常糟糕活动的。

Ok, figure out that this is an issue that was also seen by other people: apparently (at least on some phones) GPS listener works much worse if Camera is active.

<一个href=\"http://stackoverflow.com/questions/3950026/problem-with-getting-gps-data-when-using-camera$p$pview\">Problem使用相机preVIEW 时获取GPS数据

<一个href=\"http://stackoverflow.com/questions/7045659/android-losing-gps-signal-strength-on-some-phones-when-i-start-up-the-camera-and\">Android:丢失的GPS信号在某些手机上的实力,当我启动了相机和SurfaceView

相机preVIEW和GPS Android中

创建问题的Andorid对于的http:// code.google.com / p /安卓/问题/细节?ID = 20098

Created Andorid issue for that http://code.google.com/p/android/issues/detail?id=20098

如果有人有一个解决方案,请分享

If someone has a solution pls share

这篇关于Android的全球定位系统。位置监听器并不想获得一个修复:(的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆