2013-05-10 71 views
0

我正在开发一个Android应用程序(minSDK = 8),并且此应用程序具有一个地图,其中正在绘制用户的当前位置。 昨天,我修理了一些有路线制作的bug,而且都很好。然后,我不知道我做了什么,但设备的当前位置停止工作。我试图调试,并且我注意到OnLocationChanged回调从不被调用。然后,我回到使用Git的旧版本,我很积极地工作,而且它不起作用。所以我认为我的设备存在问题。然后,为了检查它,我打开了地图应用程序,它完美地工作。所以......我不知道该怎么做。我再次检查了设置 - >位置服务选项卡,并且启用了所有3个选项(GPS,网络和Google位置)。Android LocationListener停止工作

为了表明我的代码部分:

清单:

<uses-permission android:name="android.permission.INTERNET" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 

地图活动:

locationManager = (LocationManager) getApplicationContext().getSystemService(Context.LOCATION_SERVICE); 
      LocationListener locationListener = new LocationListener() { 
       @Override 
       public void onStatusChanged(String provider, int status, 
         Bundle extras) { 
       } 
       @Override 
       public void onProviderEnabled(String provider) { 
       } 
       @Override 
       public void onProviderDisabled(String provider) { 
       } 
       @Override 
       public void onLocationChanged(Location location) { 
        if (currentPosition == null){ 
         currentPosition = new LatLng(location.getLatitude(), location.getLongitude()); 
         gas_list = new ArrayList<Gasolineres>(); 
         gas_marker_list = new ArrayList<Marker>(); 
         Thread thread = new Thread(null, obteEstacions, "MagentoBackground"); 
         thread.start(); 

        } else { 
         currentPosition = new LatLng(location.getLatitude(), location.getLongitude()); 
        } 
        if (currentPosition != null){ 
         if (myPosition == null){        
          myPosition = mapView.addMarker(new MarkerOptions().position(currentPosition).snippet("Lat: " + currentPosition.latitude + "\nLon: " + currentPosition.longitude).icon(BitmapDescriptorFactory.fromResource(R.drawable.current))); 
         } else { 
          myPosition.setPosition(currentPosition); 
         } 
        } 

       } 
      }; 
      locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000, 10, locationListener);  
      locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5000, 10, locationListener); 

的事情是,我把一个断点到onLocationChanged()和它的从未打过电话我不知道该怎么做。如果我有权访问其他设备,我会尝试使用它。

回答

0

尝试重新启动手机。有时它可以帮助解决奇怪的GPS问题

1

看起来你的gps工作不正常......尝试将日志放入你的应用程序,这样你就可以在DDMS logcat中看到这个方法的时候,试试这个方法:

Log.d(TAG, "OnLocationChanged was called"); 

太尝试像GPS状态安装应用程序,看看你的GPS工作正常