i am working on a google map activity. i am trying to get the current location.it works perfectly on emulator but not getting the current location on my phone. here is the code which i am using in my application...
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
provider = locationManager.getBestProvider(criteria, false);
Location location = locationManager.getLastKnownLocation(provider);
if (location != null) {
double lat = (double) (location.getLatitude());
double lng = (double) (location.getLongitude());
Constants.lat = String.valueOf(lat);
Constants.lng = String.valueOf(lng);
}
Constants is the class where i have decalred the latitude and longitude static variables declared. This code is written in a function and it is call from onCreate method.I am getting null location everytime.I have declare below code also in manifestfile.
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Can anybody please help me ? Thanks .