I'm trying to call method requestLocationUpdates, but eventually i get an error message "cannot resolve method ". I think it's because of "this" argument, but i'm not sure. I imported LocationListener, but it didn't help me.
Here is my part of code:
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GooglePlayServicesUtil;
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.MapFragment;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MainMap extends ActionBarActivity implements LocationListener {
private void addMarker(){
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());
if(status!= ConnectionResult.SUCCESS){ // Google Play Services are not available
int requestCode = 10;
Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
dialog.show();
}else { // Google Play Services are available
googleMap.setMyLocationEnabled(true);
LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = locationManager.getBestProvider(criteria, true);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
onLocationChanged(location);
}
// troubles here
locationManager.requestLocationUpdates(provider, 20000, 10, this);
}
}
@Override
public void onLocationChanged(Location location) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
LatLng latLng = new LatLng(latitude, longitude);
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
}
}
You are importing LocationListener from the wrong package. You seem to be importing it as:
com.google.android.gms.location.LocationListener
but the requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener) method the last argument of this type:
android.location.LocationListener
as you can see here.
Changing the import statements to load android.location.LocationListener should fix the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With