Android studio 在android studio中跟踪位置(locationManager.isProviderEnabled(locationManager.GPS\U提供程序)

Android studio 在android studio中跟踪位置(locationManager.isProviderEnabled(locationManager.GPS\U提供程序),android-studio,Android Studio,我正在尝试将google api与android studio结合使用,以创建一个跟踪某人位置的代码字符串。但是,当我尝试实现locationManager.isProviderEnabled时,我收到一个错误消息:“无法解析符号‘isProviderEnabled’”尽管我有android.location.LocationManager的实现,但我真的无法找出我的代码出了什么问题,所以如果有人能帮我,那就太好了 以下是我的代码以供更多参考: else if(locationManager.

我正在尝试将google api与android studio结合使用,以创建一个跟踪某人位置的代码字符串。但是,当我尝试实现locationManager.isProviderEnabled时,我收到一个错误消息:“无法解析符号‘isProviderEnabled’”尽管我有android.location.LocationManager的实现,但我真的无法找出我的代码出了什么问题,所以如果有人能帮我,那就太好了

以下是我的代码以供更多参考:

 else if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {
                //get the latitude
                double latitude = location.getLatitude();
                //get the longitude
                double longitude = location.getLongitude();
                LatLng latLng = new LatLng(latitude, longitude);
                Geocoder geocoder = new Geocoder(getApplicationContext());
                try {
                    List<Address> addressList = geocoder.getFromLocation(latitude, longitude, 1);
                    String str = addressList.get(0).getLocality() + ",";
                    str += addressList.get(0).getCountryName();
                    mMap.addMarker(new MarkerOptions().position(latLng).title(str));
                    mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 10.2f));
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
else if(locationManager.isProviderEnabled(locationManager.GPS\U提供程序)){
locationManager.RequestLocationUpdate(locationManager.GPS_提供程序,0,0,新LocationListener(){
@凌驾
已更改位置上的公共无效(位置){
//获得纬度
双纬度=location.getLatitude();
//得到经度
double longitude=location.getLongitude();
LatLng LatLng=新LatLng(纬度、经度);
Geocoder Geocoder=新的Geocoder(getApplicationContext());
试一试{
List addressList=geocoder.getFromLocation(纬度、经度,1);
字符串str=addressList.get(0.getLocality()+“,”;
str+=addressList.get(0.getCountryName();
mMap.addMarker(新的MarkerOptions().position(latLng).title(str));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng,10.2f));
}捕获(IOE异常){
e、 printStackTrace();
}
}
  • GPSLocationService扩展了服务
  • 在GPSLocationService类中复制并粘贴onStart()
  • }


    你应该给我们更多关于你的问题的细节。
    @Override
    public void onStart(Intent intent, int startId) {
    
    locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
    listener = new MyLocationListener();
        if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
            return;
        }
        if (locationManager != null) {
          if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){           
            locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, listener);
            locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_TIME_BW_UPDATES, MIN_DISTANCE_CHANGE_FOR_UPDATES, listener);
        }
     }