gpt4 book ai didi

java - 无法解析 MY_PERMISSION_ACCESS_COURSE_LOCATION

转载 作者:太空宇宙 更新时间:2023-11-04 12:20:40 25 4
gpt4 key购买 nike

在下面的代码中,我无法解析 if block 内第 11 行的 MY_PERMISSION_ACCESS_COURSE_LOCATION,我检查了所有可能的内容,并在依赖项中编译了 google play 服务,但无法解析:|我应该怎么办 ? 我实际上每 5 分钟跟踪一次用户的位置并显示它。错误是

Error:(60, 41) error: cannot find symbol variable MY_PERMISSION_ACCESS_COURSE_LOCATION

谁能帮帮我吗?

public Location getLocation() {
try {
if ( ContextCompat.checkSelfPermission( this, android.Manifest.permission.ACCESS_COARSE_LOCATION )
!= PackageManager.PERMISSION_GRANTED )
{
ActivityCompat.requestPermissions( this, new String[]
{ android.Manifest.permission.ACCESS_COARSE_LOCATION
},
LocationServices.MY_PERMISSION_ACCESS_COURSE_LOCATION
);
Toast.makeText(GPSTracker.this, "open gps", Toast.LENGTH_SHORT).show();
}
Log.i("ok", "outside IF location");
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,
10000, // 3 sec
10, this);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);

// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);

if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
Toast.makeText(GPSTracker.this, "open it", Toast.LENGTH_SHORT).show();
}

this.canGetLocation = true;
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);

if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();

}
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

return location;
}

最佳答案

我只是检查您是否指的是 MY_PERMISSION_ACCESS_COARSE_LOCATION 而不是 MY_PERMISSION_ACCESS_COURSE_LOCATION

关于java - 无法解析 MY_PERMISSION_ACCESS_COURSE_LOCATION,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38880788/

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