gpt4 book ai didi

android - FusedLocationProviderClient 有时会给出不同的位置

转载 作者:太空宇宙 更新时间:2023-11-03 13:40:13 24 4
gpt4 key购买 nike

 public void getDeviceLocation() {
fusedLocationClient = LocationServices.getFusedLocationProviderClient(getMvpView().getActivity());
settingsClient = LocationServices.getSettingsClient(getMvpView().getActivity());
createLocationCallback();
createLocationRequest();
buildLocationSettingsRequest();
startLocationUpdates();
}


private void createLocationRequest() {
locationRequest = new LocationRequest();
locationRequest.setInterval(UPDATE_INTERVAL_IN_MILLISECONDS);
locationRequest.setFastestInterval(FASTEST_UPDATE_INTERVAL_IN_MILLISECONDS);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
}


private void createLocationCallback() {
getMvpView().showProgressDialog();
locationCallback = new LocationCallback() {
@Override
public void onLocationResult(LocationResult locationResult) {
super.onLocationResult(locationResult);
Location currentLocation = locationResult.getLastLocation();
getMvpView().showSelectedAddress(getAddressFromLatLng(currentLocation.getLatitude(), currentLocation.getLongitude()));
fusedLocationClient.removeLocationUpdates(locationCallback);
getMvpView().hideProgressDialog();
}
};
}


private void buildLocationSettingsRequest() {
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder();
builder.addLocationRequest(locationRequest);
locationSettingsRequest = builder.build();
}


private void startLocationUpdates() {
settingsClient.checkLocationSettings(locationSettingsRequest)
.addOnSuccessListener(getMvpView().getActivity(), locationSettingsResponse -> {

if (ActivityCompat.checkSelfPermission(getMvpView().getActivity(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getMvpView().getActivity(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
fusedLocationClient.requestLocationUpdates(locationRequest,
locationCallback, Looper.myLooper());

}).addOnFailureListener(getMvpView().getActivity(), e -> {
getMvpView().hideProgressDialog();
getMvpView().showErrorToast(R.string.please_enable_location);
});
}


@SuppressLint("MissingPermission")
private void startLocationUpdates() {
settingsClient.checkLocationSettings(locationSettingsRequest)
.addOnSuccessListener(getMvpView().getActivity(), locationSettingsResponse -> {
fusedLocationClient.requestLocationUpdates(locationRequest,
locationCallback, Looper.myLooper());

}).addOnFailureListener(getMvpView().getActivity(), e -> {
getMvpView().hideProgressDialog();
getMvpView().showErrorToast(R.string.please_enable_location);
});
}


private String getAddressFromLatLng(double latitude, double longitude) {
Geocoder geocoder = new Geocoder(getMvpView().getActivity(), Locale.getDefault());
List<Address> addresses = null;
try {
addresses = geocoder.getFromLocation(
latitude,
longitude,
1);
} catch (IOException e) {
e.printStackTrace();
}

Address address = addresses.get(0);
StringBuilder addressStringBuilder = new StringBuilder();
for (int i = 0; i <= address.getMaxAddressLineIndex(); i++) {
addressStringBuilder.append(address.getAddressLine(i));
}

return addressStringBuilder.toString();
}

我已将纬度、经度转换为地址文本,但在我再次查询位置后,即使我没有离开当前位置,地址也会发生变化,同时也启用了电话设置的准确性。问题是当我总是查询如果我的纬度、经度位置没有改变,它应该给我相同的位置地址。

最佳答案

FusedLocationProviderClient 意味着结合了 gps 和 google-translating-received-wlan-cellphone-tower-signals-to-lat-lon。

google-translating-received-wlan-cellphone-tower-signals-to-lat-lon 是一种不精确的启发式方法,除其他因素外,它还取决于您的手机连接到哪个手机信号塔(以及谷歌在哪里有纬度/经度)每个塔)以及最强的 3 个手机塔的强度。

如果你的手机改变了它的手机塔连接那么对于谷歌算法你的手机位置已经改变了。

如果您的手机可以接收 3 个以上的手机信号塔,那么最强的 3 个手机信号塔也会发生变化,具体取决于每个手机信号塔的流量。

GPS 接收器消耗大量能量。当启用 gps-energy-optimisation 时,可能还会存在导致融合位置跳跃的 gps 精度问题。

我第一次用我的新手机进行寻宝时学到了这一点,我想知道为什么我自己的位置在 map 上跳跃了

关于android - FusedLocationProviderClient 有时会给出不同的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53666679/

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