我正在编写一个应用程序,在谷歌地图中显示您的位置…
到目前为止,这么好……它确实显示了我的位置
问题是,如果我正在移动(或者确实如此,但仅在一段时间后),这个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