为什么我的位置和标记有不同的位置?在添加标记之前,我单击 float 按钮,当我单击该按钮时,我从 LocationManager
调用 getLatitude
和 getLongitude
。这类似于准备好 map 并移动相机,所以我认为标记和 mylocation 必须相同:
这是我的代码:
private class MyLocationListeners implements LocationListener {
@Override
public void onLocationChanged(Location location) {
longitude = null;
latitude = null;
longitude = String.valueOf(location.getLongitude());
Log.d(TAG, "onLocationChanged1: " + longitude);
latitude = String.valueOf(location.getLatitude());
Log.d(TAG, "onLocationChanged2: " + latitude);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
}
我设置 MyLocationListener
的代码:
locationListener = new MyLocationListeners();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
5000,
10,
locationListener
);
最佳答案
My location layer使用它自己的位置提供者,既不是融合位置提供者也不是位置管理器。来自 the documentation :
A GoogleMap object has a built-in location provider for its my-location layer, but it can be replaced with another one that implements this interface.
此外,我的位置层、融合位置提供程序和位置管理器可以获得不同的位置(这取决于提供程序、GPS 和网络可用性,...)。
您可以使用 GoogleMap.setLocationSource
方法替换我的位置图层的默认位置提供程序。
关于android - 我的位置和标记有不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38394172/