2011-06-27 36 views
0

我是Android新手,我試圖在我的應用程序中檢索GPS數據。 我使用下面的代碼 LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);locationmanager.requestForLocation不適用於摩托羅拉backflip&samsung galaxy

if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER)){ 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 1000L, 500.0f, this); 
} 

而且我的課我已經重寫了以下方法

public void onLocationChanged(Location location) 
{ 
    String currentLocation = "The location is changed to Lat: " + location.getLatitude()+ " Lng: " + location.getLongitude(); 
    Toast.makeText(context, currentLocation, Toast.LENGTH_LONG); 
} 

但它沒有顯示任何東西,這是與摩托羅拉只發生後空翻&三星Galaxy設備。 請讓我知道如果我做錯了什麼。提前致謝。

Thansk, Devanand

回答

3

你忘了使用Toast.makeText(...).show();

0

您確定此代碼顯示其他手機的東西? Neeraj回答說,你必須添加.show()toast。

如果這不是問題&你剛剛在這裏錯過了,那麼你可能遇到了我也面臨的問題。一段代碼類似於你的工作完美摩托羅拉Atrix,但不在摩托羅拉Droid

這是我的解決方法。如果GPS不可用,我會回到網絡供應商。像這樣:

//Start with fine location using GPS 
String locationProviderInit = LocationManager.GPS_PROVIDER; 
if ((locationProviderInit == null) || 
     !(mLocationManager.isProviderEnabled(locationProviderInit))) 
{ 
//If GPS not available, fall back on coarse location 
    locationProviderInit = LocationManager.NETWORK_PROVIDER; 
} 

希望這有助於!