2014-10-04 22 views
0

我試圖獲得位置管理器中的活動工作在我的Android應用程序,但它不斷給我的錯誤「無法解析方法requestLocationUpdates」的Android的LocationManager - 不能解析方法

我把這個代碼我的OnCreate(其他例子中):

// Acquire a reference to the system Location Manager 
LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); 

// Define a listener that responds to location updates 
LocationListener locationListener = new LocationListener() { 
public void onLocationChanged(Location location) { 
    // Called when a new location is found by the network location provider. 
    makeUseOfNewLocation(location); 
} 

public void onStatusChanged(String provider, int status, Bundle extras) {} 

public void onProviderEnabled(String provider) {} 

public void onProviderDisabled(String provider) {} 
    }; 

// Register the listener with the Location Manager to receive location updates 
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListener); 

我想用我自己的「OnLocationChanged」方法來更新與用戶位置的地圖,但我不明白,爲什麼我得到這個錯誤。

任何想法,爲什麼我得到錯誤?

有更好的更現代的方式來實現位置更新嗎?

謝謝!

回答

2

我建議你看看Google Play服務中的新FusedLocationProviderApi。從文檔:

的谷歌位置服務API,谷歌Play的一部分服務, 提供了一個更強大的,高層次的框架,自動 處理位置提供者,用戶移動和定位精度。它還根據您提供的參數 處理位置更新調度。在大多數情況下,通過使用位置服務API,您可以獲得更好的電池性能以及更準確的電池性能 。

+0

酷感謝靈光,你把正確的方向。我發現這個例子:http://stackoverflow.com/a/25173057/2063149 – Pabs 2014-10-04 18:21:38

0

確保你是正確的LocationClient,應該是com.google.android.gms.location.LocationClient重要的,你可能會被導入android.location.LocationClient

+0

'LocationClient'已被棄用。 – Emmanuel 2014-10-04 18:23:16

+0

我的不好,最近沒有檢查過更新,謝謝指出。 – NightwareSystems 2014-10-04 18:29:24

+0

今天剛剛發現,我自己,哈哈 – Emmanuel 2014-10-04 18:30:01

相關問題