recently I changed from LocationManager to the new LocationClient, but I
have a strange problem:
When I change from one location provider to another(going to
config->location settings) sometimes it stops reciving locations updates,
and, for some reason all the others app in the device that uses location
also stop reciving updates(i tested on google maps and a test mapview
aplication of my own)
This is the code:
public class GeoLocationClient {
LocationClient mLocationClient;
Location currentLocation;
MainActiviy app;
public GeoLocationClient(MainActiviy app) {
// TODO Auto-generated constructor stub
this.app = app;
startLocationTracking();
}
protected void startLocationTracking() {
int a = GooglePlayServicesUtil.isGooglePlayServicesAvailable(app);
Log.v("goglelaksjda",a+"");
if (mLocationClient != null) {
Log.v("goglelaksjda","not null");
}
if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(amanda) == 0) {
if (mLocationClient == null) {
mLocationClient = new LocationClient(amanda,
mConnectionCallbacks, mConnectionFailedListener);
}
if(!mLocationClient.isConnected()) {
mLocationClient.connect();
}
}
}
public void disconect() {
mLocationClient.disconnect();
}
private ConnectionCallbacks mConnectionCallbacks = new
ConnectionCallbacks() {
@Override
public void onDisconnected() {
Log.v("on disconected",":(");
}
@Override
public void onConnected(Bundle arg0) {
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setFastestInterval(1000);
locationRequest.setInterval(1000).setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationClient.requestLocationUpdates(locationRequest,
mLocationListener);
}
};
private OnConnectionFailedListener mConnectionFailedListener = new
OnConnectionFailedListener() {
@Override
public void onConnectionFailed(ConnectionResult arg0) {
Log.v("locationclient", "ConnectionFailed");
}
};
private LocationListener mLocationListener = new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.v("location",location.getProvider()+"");
Log.v("location",location.getLatitude()+"");
Log.v("location",location.getLongitude()+"");
Log.v("location",location.getAccuracy()+"");
Log.v("location",location.getTime()+"");
currentLocation = location;
}
};
}
I the MainActivity onCreate i initialize it:
mGeoLocationClient = new GeoLocationClient(this);
In onDestroy i stop it:
mGeoLocationClient.disconect();
And in onResume i start the location updates again:
mGeoLocationClient.startLocationTracking();
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
---
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.