gpt4 book ai didi

android - 当前位置未显示在摩托罗拉设备的 map 中

转载 作者:行者123 更新时间:2023-11-30 04:56:11 26 4
gpt4 key购买 nike

我在我的应用程序中使用谷歌地图,代码工作正常并显示当前位置,我不知道为什么我的代码工作但只在三星设备上,而不是在摩托罗拉......我不知道我是否错过了一些许可对于其他设备.. 如果有人能给我一些帮助..会很好这是我的代码

 protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getLocationPermission();
initMap();
}
private void getLocationPermission(){
String[] permission ={
Manifest.permission.ACCESS_COARSE_LOCATION};
if (ContextCompat.checkSelfPermission(this.getApplicationContext(),Manifest.permission.ACCESS_FINE_LOCATION)== PackageManager.PERMISSION_GRANTED){
if(ContextCompat.checkSelfPermission(this.getApplicationContext(),
Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED){
mLocationPermissionsGranted = true;
getDeviceLocation();
}else{
ActivityCompat.requestPermissions(this,permission,
LOCATION_PERMISSION_REQUEST_CODE);
}
}else{
ActivityCompat.requestPermissions(this,
permission,
LOCATION_PERMISSION_REQUEST_CODE);
}
}
private void initMap() {
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync((OnMapReadyCallback) this);
}
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

if (mLocationPermissionsGranted) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mMap.setMyLocationEnabled(true);
}
}
private void getDeviceLocation(){
Log.d("MapsActivity.this", "getDeviceLocation: getting the devices current location");

mFusedLocationProviderClient = LocationServices.getFusedLocationProviderClient(this);

try{
if(mLocationPermissionsGranted){

final Task location = mFusedLocationProviderClient.getLastLocation();
location.addOnCompleteListener(new OnCompleteListener() {
@Override
public void onComplete(@NonNull Task task) {
if(task.isSuccessful()){
Log.d("MapsActivity.this", "onComplete: found location!");
Location currentLocation = (Location) task.getResult();

moveCamera(new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude()),
DEFAULT_ZOOM,"My location");

}else{
Log.d("MapsActivity.this", "onComplete: current location is null");
Toast.makeText(MainActivity.this, "unable to get current location", Toast.LENGTH_SHORT).show();
}
}
});
}
}catch (SecurityException e){
Log.e("MapsActivity.this", "getDeviceLocation: SecurityException: " + e.getMessage() );
}
}

最佳答案

我刚刚更改了设备的配置,这三个中的一个必须工作正常

关于android - 当前位置未显示在摩托罗拉设备的 map 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59108440/

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