Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/363.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/214.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法将com.google.android.gms.location.LocationListener转换为android.location.LocationListener_Java_Android_Maps_Listener - Fatal编程技术网

Java 无法将com.google.android.gms.location.LocationListener转换为android.location.LocationListener

Java 无法将com.google.android.gms.location.LocationListener转换为android.location.LocationListener,java,android,maps,listener,Java,Android,Maps,Listener,我得到以下错误 Error:(197, 28) error: no suitable method found for requestLocationUpdates (String,long,float,com.google.android.gms.location.LocationListener) method LocationManager.requestLocationUpdates (String,long,float,android.location.LocationListe

我得到以下错误

Error:(197, 28) error: no suitable method found for requestLocationUpdates    (String,long,float,com.google.android.gms.location.LocationListener) method LocationManager.requestLocationUpdates (String,long,float,android.location.LocationListener) is not applicable
(argument mismatch; com.google.android.gms.location.LocationListener cannot be converted to android.location.LocationListener)
method LocationManager.requestLocationUpdates(String,long,float,PendingIntent) is not applicable
(argument mismatch; com.google.android.gms.location.LocationListener cannot be converted to PendingIntent)

method LocationManager.requestLocationUpdates(long,float,Criteria,PendingIntent) is not applicable
(argument mismatch; String cannot be converted to long)
当试图运行我的代码时,尽管这一行在Android Studio中用红色下划线

LocationManager.RequestLocationUpdate(LocationManager.GPS\u提供程序、位置\u刷新\u时间、, 位置(刷新距离,位置侦听器)

我仍然没有找到不匹配的原因,如果有任何提示或帮助,我将不胜感激。

这是我的位置侦听器:

private final LocationListener LocationListener = new LocationListener() {
        @Override
        public void onLocationChanged(final Location location) {
            updateLocation(location);
        }
它调用以下updateLocation:

 protected void updateLocation(Location location) {

      if (location != null && gpsFix == true) {
          addPoint(location);

          if (previousLocation != null)
              distanceTraveled += location.distanceTo(previousLocation);
      }
      previousLocation = location;
  }
哪个叫addPoint

  public void addPoint(Location location) {
      locations.add(location);
  }
位置是位置对象的数组列表。除此之外,我还有以下声明:

 float LOCATION_REFRESH_DISTANCE = 1;
 long LOCATION_REFRESH_TIME = 100;
编辑:当我尝试这个

LocationManager.RequestLocationUpdate(LocationManager.GPS\u提供程序、位置\u刷新\u时间、, 位置\刷新\距离, (android.location.LocationListener)LocationListener)

我看到以下情况:无法从静态上下文引用非静态方法“requestLocationUpdates(…)”

以下是我的作品:

import android.content.Context;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.graphics.Paint;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.os.PowerManager;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.FrameLayout;
import android.location.LocationListener;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
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;
import com.google.android.gms.maps.model.PolylineOptions;
import java.util.ArrayList;
import java.util.List;
解决方案

if (ActivityCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED){
        float LOCATION_REFRESH_DISTANCE = 1;
        long LOCATION_REFRESH_TIME = 100;
        mlocationListener = new LocationListener() {
            @Override
            public void onLocationChanged(Location location) {

                updateLocation(location);
            }

            @Override
            public void onStatusChanged(String s, int i, Bundle bundle) {

            }

            @Override
            public void onProviderEnabled(String s) {

            }

            @Override
            public void onProviderDisabled(String s) {

            }
        };

        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,LOCATION_REFRESH_TIME, LOCATION_REFRESH_DISTANCE, mlocationListener);
    }
我有一个大写字母L在位置经理。这就是为什么我没有访问objectlocationmanager(使用一个小l)。就这些

方法LocationManager.requestLocationUpdates(大写L)是一个静态方法,属于类(属于类型而不是对象),与表示该类的任何对象没有关系,或者换句话说,与类型LocationManager中的任何对象没有关系