下面是來自official guide示例代碼(帶小的修改):
// 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) {
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.GPS_PROVIDER, 0, 0, locationListener);
在這裏,你剛剛從GPS請求更新,並儘快收到的位置,你會得到一個回調呼叫。
這是爲我做的!當然,就我而言,我沒有或需要位置,直到它_changes_。如果我從'onLocationChanged'調用我的下一個方法,我甚至不需要聽GPS定位。感謝名單! – dhafnar
我做了同樣的代碼..但onLocationChanged()永遠不會被調用..我不知道是什麼問題 –