2011-11-30 134 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