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

努尔丁·瓦尔塔尼(Noureddine Ouertani)

我收到以下错误

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.requestLocationUpdates(LocationManager.GPS_PROVIDER,LOCATION_REFRESH_TIME,LOCATION_REFRESH_DISTANCE,LocationListener);

我仍然没有找到不匹配的来源,感谢您提供的任何提示或帮助

这是我的位置监听器:

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);
  }

位置是位置对象的ArrayList。除此之外,我还有以下声明:

 float LOCATION_REFRESH_DISTANCE = 1;
 long LOCATION_REFRESH_TIME = 100;

编辑:当我尝试这个

LocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,LOCATION_REFRESH_TIME,LOCATION_REFRESH_DISTANCE,(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;
努尔丁·瓦尔塔尼(Noureddine Ouertani)

解决方案

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);
    }

我在LocationManager中有一个大写的L。这就是为什么我没有访问Object locationManager(带有一个小l)的原因。就这样!

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

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

无法转换为android中的com.google.android.gms.location.LocationListener异常

来自分类Dev

Android Wear:MainActivity无法转换为com.google.android.gms.location.LocationListener

来自分类Dev

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this); 尝试转换为com.google.android.gms.location.LocationListener)

来自分类Dev

无法将主要活动投射到位置侦听器,即 com.google.android.gms.location.LocationListener

来自分类Dev

导入com.google.android.gms.location.LocationClient无法解析

来自分类Dev

导入com.google.android.gms.location.LocationClient无法解析

来自分类Dev

无法解析导入com.google.android.gms.location.ActivityRecognitionResult

来自分类Dev

在“ com.google.android.gms:play-services-location:9.4.0”中,无法导入导入com.google.android.gms.location.places.Places

来自分类Dev

无法解决:com.google.android.gms:play-services-location:9.6.1

来自分类Dev

java.lang.NoSuchFieldError:com.google.android.gms.R $ string.location_client_powered_by_google

来自分类Dev

找不到方法glt.a引用的类'com.google.android.gms.location.internal.ParcelableGeofence

来自分类Dev

com.google.android.gms.location.internal.ParcelableGeofence”,从方法gls.a引用

来自分类Dev

找不到类'com.google.android.gms.location.internal.ParcelableGeofence

来自分类Dev

错误重复输入:com / google / android / gms / location / places / zzj.class

来自分类Dev

找不到类'com.google.android.gms.location.internal.ParcelableGeofence

来自分类Dev

com.google.android.gms.location.internal.ParcelableGeofence”,从方法gls.a引用

来自分类Dev

错误重复输入:com / google / android / gms / location / places / zzj.class

来自分类Dev

格式化计算机后无法解析导入com.google.android.gms.location.LocationClient

来自分类Dev

java.lang.UnsupportedOperationException:无法实例化接口!接口名称:com.google.android.gms.location.places.Place

来自分类Dev

例外:尝试在空对象引用上调用虚拟方法'int com.google.android.gms.location.LocationRequest.b()'

来自分类Dev

android.widget.RadioButton无法转换为com.google.android.gms.ads.AdView

来自分类Dev

com.google.android.gms。无法完成

来自分类Dev

按钮无法转换为com.google.android.gms.ads.adView

来自分类Dev

Android-LocationListener无法在方法上定义“ this”

来自分类Dev

尝试添加 com.google.anddroid.gms.location.locationRequest 后,我的应用程序不断崩溃

来自分类Dev

Android LocationListener不起作用

来自分类Dev

Android 5.0 IllegalArgumentException:服务意图必须明确:在com.google.android.location.internal.GoogleLocationManagerService.START

来自分类Dev

无法解决Eclips错误com.google.android.gms.ads

来自分类Dev

无法解析com.google.android.gms.plus.Plus类

Related 相关文章

  1. 1

    无法转换为android中的com.google.android.gms.location.LocationListener异常

  2. 2

    Android Wear:MainActivity无法转换为com.google.android.gms.location.LocationListener

  3. 3

    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient,this); 尝试转换为com.google.android.gms.location.LocationListener)

  4. 4

    无法将主要活动投射到位置侦听器,即 com.google.android.gms.location.LocationListener

  5. 5

    导入com.google.android.gms.location.LocationClient无法解析

  6. 6

    导入com.google.android.gms.location.LocationClient无法解析

  7. 7

    无法解析导入com.google.android.gms.location.ActivityRecognitionResult

  8. 8

    在“ com.google.android.gms:play-services-location:9.4.0”中,无法导入导入com.google.android.gms.location.places.Places

  9. 9

    无法解决:com.google.android.gms:play-services-location:9.6.1

  10. 10

    java.lang.NoSuchFieldError:com.google.android.gms.R $ string.location_client_powered_by_google

  11. 11

    找不到方法glt.a引用的类'com.google.android.gms.location.internal.ParcelableGeofence

  12. 12

    com.google.android.gms.location.internal.ParcelableGeofence”,从方法gls.a引用

  13. 13

    找不到类'com.google.android.gms.location.internal.ParcelableGeofence

  14. 14

    错误重复输入:com / google / android / gms / location / places / zzj.class

  15. 15

    找不到类'com.google.android.gms.location.internal.ParcelableGeofence

  16. 16

    com.google.android.gms.location.internal.ParcelableGeofence”,从方法gls.a引用

  17. 17

    错误重复输入:com / google / android / gms / location / places / zzj.class

  18. 18

    格式化计算机后无法解析导入com.google.android.gms.location.LocationClient

  19. 19

    java.lang.UnsupportedOperationException:无法实例化接口!接口名称:com.google.android.gms.location.places.Place

  20. 20

    例外:尝试在空对象引用上调用虚拟方法'int com.google.android.gms.location.LocationRequest.b()'

  21. 21

    android.widget.RadioButton无法转换为com.google.android.gms.ads.AdView

  22. 22

    com.google.android.gms。无法完成

  23. 23

    按钮无法转换为com.google.android.gms.ads.adView

  24. 24

    Android-LocationListener无法在方法上定义“ this”

  25. 25

    尝试添加 com.google.anddroid.gms.location.locationRequest 后,我的应用程序不断崩溃

  26. 26

    Android LocationListener不起作用

  27. 27

    Android 5.0 IllegalArgumentException:服务意图必须明确:在com.google.android.location.internal.GoogleLocationManagerService.START

  28. 28

    无法解决Eclips错误com.google.android.gms.ads

  29. 29

    无法解析com.google.android.gms.plus.Plus类

热门标签

归档