LocationManager首次在三星设备中未提供准确位置



我正在获取用户的当前位置,当我第一次点击时,它显示不同的位置(即距离我的当前位置超过10km(如果我再次点击按钮,它会显示的确切当前位置

注意:问题发生在三星M系列和A系列-安卓版本10

在我的案例中,我解决了这样的问题,

以前我用这种

location_gps_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vw) {
if (location != null) {

double latitude = location.getLatitude();
double longitude = location.getLongitude();

LatLng cur_Latlng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(cur_Latlng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(17));

}
});

相反,我更新了这样,它为我工作

location_gps_image.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View vw) {
if (location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();

LatLng cur_Latlng = new LatLng(latitude, longitude);
CameraUpdate currentLocation = CameraUpdateFactory.newLatLngZoom(cur_Latlng, 17);
googleMap.animateCamera(currentLocation);
}
});

最新更新