2014-09-25 49 views
-1

我正在使用Gps獲取當前經緯度,在我的應用程序中,它與android 2.3.3很好地工作,甚至在我的一些更高版本的android設備上工作,但有時在一些設備中,它的行爲正好相反,儘管GPS顯示錯誤信息:GPS未連接,請打開GPS,這是我在gps未檢測到時使用的消息。任何人都可以請幫助我嗎? 下面是我的檢測並獲得GPSGps在某些應用程序中不工作有時用於a​​ndroid

private void bindgeocodelocation() { 
    latlong = new ArrayList<String>(); 

    latlong = GeneralFunction.getcurrentlocation(Search.this); 
    if (latlong == null) { 
     LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     Location loc = lm 
       .getLastKnownLocation(LocationManager.NETWORK_PROVIDER); 
     lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 100, 1, 
       locationListener); 
     if (loc != null) { 
      latlong = new ArrayList<String>(); 
      latlong.add("" + loc.getLatitude()); 
      latlong.add("" + loc.getLongitude()); 
     } else if (lm != null) { 
      lm.removeUpdates(locationListener); 
     } 
    } 

} 

private final LocationListener locationListener = new LocationListener() { 
    public void onLocationChanged(Location location) { 

     try { 
      latlong = new ArrayList<String>(); 
      latlong.add(location.getLatitude() + ""); 
      latlong.add(location.getLongitude() + ""); 
      // webviewdata(); 
     } catch (Exception e) { 
      Log.e("Error", e.getMessage().toString()); 
     } 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Log.i("Info", "Provider disable"); 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // TODO Auto-generated method stub 

    } 
}; 
+0

崗位培訓相關代碼 – 2014-09-25 06:38:10

+0

發佈的代碼 – 2014-09-25 06:40:49

+0

我認爲你必須使用最好的供應商insted的的LocationManager.NETWORK_PROVIDER – 2014-09-25 06:42:10

回答

0

然後,如果你作出這樣的設備室外一段時間,它可能工作代碼。在一些低端設備中,gps可能無法正常工作。否則,請嘗試升級GooglePlayServices。此外,我建議你使用多個提供商而不是隻有一個NETWORK_PROVIDER

+0

實際上,她面臨的問題,她無法檢測GPS在某些設備上或關閉,所以錯誤的方向回答你給了 – 2014-09-25 06:40:31

+0

我面對這樣的問題在低端設備。讓她試試這個。它可能工作。 – Supriya 2014-09-25 06:45:37

+0

另外我建議你使用多個提供商而不是隻有一個NETWORK_PROVIDER – Supriya 2014-09-25 06:47:35

0

有時特定設備的谷歌播放服務已過時 我遇到了類似的問題。 你的代碼看起來不錯 唯一的問題可能是谷歌playe服務已經過時。

相關問題