如何经常更新GPS位置?

Jua*_*uan 4 gps android

我正在编写一个应用程序,在谷歌地图中显示您的位置...到目前为止,这么好......它确实显示了我的位置

问题是,如果我正在移动(或者确实如此,但仅在一段时间后),这个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...
Run Code Online (Sandbox Code Playgroud)

有人知道我错过了什么吗?

Cra*_*igy 5

您正在使用的方法调用是requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener),并且您告诉它仅每35000ms或每35秒为您提供一次更新.尝试将该数字降低到适合您的数量.数字越小意味着电池使用量越多.

如果你想要一个指标MapView,请查看MyLocationOverlay.