gpt4 book ai didi

ANDROID locationManager.requestLocationUpdates无法解析?

转载 作者:行者123 更新时间:2023-11-29 14:37:21 28 4
gpt4 key购买 nike

我不明白为什么无法解析locationManager.requestLocationUpdates。我搜索了答案,它说您必须导入不再使用的 LocationClient。

这是我如何找到我当前的定位方法。如果我遗漏了什么,请告诉我。

 private void setUpMap() {
// Enable MyLocation Layer of Google Map
mMap.setMyLocationEnabled(true);

// Get LocationManager object from System Service LOCATION_SERVICE
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

// Create a criteria object to retrieve provider
Criteria criteria = new Criteria();
// Get the name of the best provider
String provider = locationManager.getBestProvider(criteria,true);



LocationListener locationChangeListener = new LocationListener() {
public void onLocationChanged(Location l) {
if (l != null) {
Log.i("SuperMap", "Location changed : Lat: " + l.getLatitude() + " Lng: " +
l.getLongitude());
}
}

public void onProviderEnabled(String p) {
}

public void onProviderDisabled(String p) {
}

public void onStatusChanged(String p, int status, Bundle extras) {
}

};
locationManager.requestLocationUpdates(provider,0,0,locationChangeListener);



// Get Current Location
Location myLocation = locationManager.getLastKnownLocation(provider);

// set map type
mMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);

// Get latitude of the current location
double latitude = myLocation.getLatitude();
// Get longitude of the current location
double longitude = myLocation.getLongitude();

// Create a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);

// Show the current location in Google Map
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));

// Zoom in the Google Map
mMap.animateCamera(CameraUpdateFactory.zoomTo(14));
mMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!").snippet("Consider yourself located"));
}

这是我的进口

import android.content.Context;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationManager;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;



import com.google.android.gms.location.LocationListener;
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.FusedLocationProviderApi;

import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.GeofencingApi;

最佳答案

android.location 包中导入 LocationListener 接口(interface),因为当前您正在从 com.google.android.gms.location 包中导入,但是 requestLocationUpdates 方法将 android.location.LocationListener 作为最后一个参数。

改变:

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

import android.location.LocationListener;

关于ANDROID locationManager.requestLocationUpdates无法解析?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28935694/

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