Wednesday, 7 August 2013

onLocationChanged not called on some devices

onLocationChanged not called on some devices

This is a question which has been asked numerous times but I could not
find a solution which always works.
I am developing an application using Fused location provider. In the
onConnection method, I am requesting for location updates and the
application logic will be initiated once a location fix is generated and
onLocationChanged is called. (Please refer to my code below).
Problem onLocationChanged method is never clled on some devices. I use a
Samsung Tab 2 and a Samsung Galaxy Grand for testing. This code works
perfectly fine on the Tab 2 but does not work on Grand. By does not work I
mean that locationClient gets connected but onLocationChanged is never
called.
Earlier I used the location manager for getting location and in that
implementation also, the same problem was faced. So I tried implementing
the fused location provider but still the same problem.
Can anyone help me out with this issue. Is there something I am missing here.
public class MainActivity extends Activity implements
GooglePlayServicesClient.ConnectionCallbacks,OnConnectionFailedListener,
LocationListener {
LocationClient locationclient;
LocationRequest lr;
Location loc1;
static String address;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationclient = new LocationClient(this,this,this);
locationclient.connect();
}
@Override
public void onConnected(Bundle arg0) {
// TODO Auto-generated method stub
lr=LocationRequest.create();
lr.setInterval(100);
locationclient.requestLocationUpdates(lr, this);
Log.d("LocationClient","On Connected");
}
@Override
public void onDisconnected() {
// TODO Auto-generated method stub
locationclient.disconnect();
}
@Override
public void onConnectionFailed(ConnectionResult arg0) {
// TODO Auto-generated method stub
}
@Override
public void onLocationChanged(Location loc) {
// TODO Auto-generated method stub
// Application Logic
Log.d("LocationClient","Last Known Location LC:" + loc.getLatitude() +
"," + loc.getLongitude());
}
}

No comments:

Post a Comment