2013-05-10 70 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工作正常