gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:54:22 28 4
gpt4 key购买 nike

我已经在 Android 上设置了一个基于位置的 map ,但是当我尝试调用时:LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

Android studio 试图让我将其转换为

LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, (com.google.android.gms.location.LocationListener) this);

然而,这会导致应用程序在调用时崩溃。

我的应用有以下位置代码:

import android.content.IntentSender;
import android.location.Location;
import android.location.LocationListener;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
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.location.LocationServices;

import java.util.List;

import model.SiteModel;
import model.SqlHelper;

public class FindNearestLocationMap extends FragmentActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, LocationListener {

private GoogleMap mMap; // Might be null if Google Play services APK is not available.

private GoogleApiClient mGoogleApiClient;

public static final String TAG = FindNearestLocationMap.class.getSimpleName();

private final static int CONNECTION_FAILURE_RESOLUTION_REQUEST = 9000;

private LocationRequest mLocationRequest;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_find_nearest_location_map);

mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API)
.build();

mLocationRequest = LocationRequest.create()
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
.setInterval(10 * 1000) // 10 seconds, in milliseconds
.setFastestInterval(1 * 1000); // 1 second, in milliseconds

setUpMapIfNeeded();
}

@Override
protected void onResume() {
super.onResume();
setUpMapIfNeeded();
mGoogleApiClient.connect();
}

@Override
protected void onPause() { //////ERROR IS HERE////////
super.onPause();
if (mGoogleApiClient.isConnected()) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, (com.google.android.gms.location.LocationListener) this);
mGoogleApiClient.disconnect();
}
}
....

我拥有类所需的所有已实现方法,并且能够运行该程序。仅当 onPause 被调用时它才会中断关于我应该做什么的任何想法?

谢谢。

最佳答案

您对 LocationListener 使用了错误的导入。你有:

import android.location.LocationListener;

这是遗留的 LocationListener 而不是 Fused Location Provider 的监听器:

import com.google.android.gms.location.LocationListener;

关于android - LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, 这个);尝试转换为 com.google.android.gms.location.LocationListener),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28508547/

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