gps更新频率 android,android – 如何经常更新gps位置?

博主在开发一个Android应用,遇到了一个问题:GPS位置不会实时更新,只有在移动一段时间后才会改变。他们尝试了使用NETWORK_PROVIDER和GPS_PROVIDER请求位置更新,但效果不理想。解决方案是使用MyLocationOverlay类来实现类似谷歌地图原生的定位更新,即显示一个闪烁的蓝点以跟踪移动位置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

我正在编写一个应用程序,在谷歌地图中显示您的位置…

到目前为止,这么好……它确实显示了我的位置

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

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

解决方法:

如果您想在MapView上使用指标,请查看MyLocationOverlay.

标签:android,gps

来源: https://codeday.me/bug/20190530/1185381.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值