当我调用LocationManger时,无法解析方法'requestLocationUpdate'

时间:2016-05-04 03:49:29

标签: java android google-maps android-studio import

我正在尝试使用locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); 但我得到一个错误说: enter image description here

我认为它可能来自错误的LocationListerner库,但这里是我导入的所有库

import android.Manifest;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.widget.Toast;

import com.example.ahmed.mob_review.MainActivity;
import com.example.ahmed.mob_review.R;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

EDITED

我认为它来自最后一个参数this enter image description here

2 个答案:

答案 0 :(得分:1)

试试这个......

locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,0, (LocationListener) this);

答案 1 :(得分:1)

解决了

  • 活动应从LocationListener
  • 实施
  • 我要将this个活动投放到LocationListener
  • 在我请求onLocationChangedNETWORK_PROVIDER 之前,我不会调用
  • GPS_PROVIDER

<强>如:

    locationManager.requestLocationUpdates(locationManager.GPS_PROVIDER, 0, 0, (LocationListener) this);
    locationManager.requestLocationUpdates(locationManager.NETWORK_PROVIDER, 0, 0, (LocationListener) this);

现在它起作用了:)