我尝试获取当前位置。首先,我创建了LocationListener:
public LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(final Location location) {
// Getting latitude of the current location
double latitude = location.getLatitude();
// Getting longitude of the current location
double longitude = location.getLongitude();
// Creating a LatLng object for the current location
myLocation = new LatLng(latitude, longitude);
}
};
in onCreate方法我尝试在LocationManager上调用requestLocatonUpates:
mLocationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,1000,500f,mLocationListener);
但是我收到了一个错误:
无法解析方法requestLocationUpdates(java.langString,long,float,com.google.android.gms.location.LocationListener)
答案 0 :(得分:0)
requestLocationUpdates是FusedLocationAPi中提供的方法。您应该使用LocationServices.FusedLocationApi.requestLocationUpdates方法。 因此,您必须创建googleApiClient和位置请求。 您可以在此处找到它:https://developer.android.com/training/location/index.html。