gpt4 book ai didi

android - 如何经常更新GPS位置?

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:41:35 24 4
gpt4 key购买 nike

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

问题是如果我在移动,这个 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...

有人知道我是否遗漏了什么吗?

最佳答案

您正在使用的方法调用是 requestLocationUpdates(String provider, long minTime, float minDistance, LocationListener listener) ,并且您告诉它仅每 35000 毫秒或每 35 秒更新一次。尝试将该数字降低到适合您的水平。不过,较低的数字意味着更多的电池使用量。

如果您想要在 MapView 上显示一个指示器,请查看 MyLocationOverlay .

关于android - 如何经常更新GPS位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8331201/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com