I am new to Android. I am using the following code but sometimes on Location changed is not called and Location object returns null... Or sometimes it is getting nearest value only but i need accurate same as OLA cabs tracking.
My Code as Follows
MyLocationListener mll=new MyLocationListener();
LocationManager locationManager = (LocationManager)context.getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
mll
);
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER))
{
Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null)
Log.e("TAG","LocationDetected ");
Location can be got by mainly two types of providers:
So, you can use both according to accuracy, availability and efficiency by using Criteria . Here is a snippet of my project code-
For faster yet accurate location tracking, you may use latest Google Play API which is recommended by Google. Here is the best example I got regarding Google Play/Fused API - http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/