2011-11-30 81 views
4

我寫,顯示在谷歌地圖所在位置的應用程序... 到目前爲止,這麼好......它確實顯示了我的位置正確如何頻繁更新GPS位置?

的問題是,這款GPS未更新,如果我移動(或它,但只有一段時間後)

有沒有人知道如何做到這一點像本地谷歌地圖(對於Android)呢? 這是,如果你點擊「我的位置」它顯示了一個閃爍的藍點,你運動時發生改變......

這是我的代碼:

//Initializing the listeners   
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 35000, 10, networkLocationListener); 
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 35000, 10, gpsLocationListener); 



//and now, in both 'networkLocationListener' and 'gpsLocationListener' 
//I overwrite the method 'onLocationChanged': 

@Override 
public void onLocationChanged(Location location) { 
    Log.i("test", "New network location: "+location.getLatitude()+ 
        " , "+location.getLongitude()); 
    myLongitude= location.getLongitude(); 
    myLatitude= location.getLatitude(); 
} 

//and the variables myLongitude and myLatitude are the only ones that I need to display my 
//position in the map... 

有誰知道,如果我失去了一些東西?

回答

1

你不會想這樣永遠離開它,但如果你還沒有給出一個鏡頭,可能需要將minTime和minDistance值設置爲零。

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, gpsLocationListener); 

如果minTime大於0,則的LocationManager可能休息minTime毫秒位置更新之間以節省電力。如果minDistance大於0,則只有設備通過minDistance米移動時纔會廣播位置。爲了獲得通知儘可能頻繁地,這兩個參數設置爲0。

- requestLocationUpdates Reference