I am using the following code to get my current location. But the problem I am facing is, it always returns 0.0 for latitude and longitude. I have turned on the GPS settings in the phone and set all the permissions. But still I am facing this.
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
customLocationListener = new CustomLocationListener();
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
customLocationListener);
class CustomLocationListener implements LocationListener{ ............
public void onLocationChanged(Location argLocation) {
if(location != null) {
int latitude=(int)(argLocation.getLatitude()*1E6);
int longitude=(int)(argLocation.getLongitude()*1E6);
}
} ........ }
Do any one of you know why?
Note : My activity extends MapActivity not Location Listener
CustomLocationManager.Java
LocationValue.Java
YourActivity.Java
try this way
in mylocationlistener set your location object
Here, when we give a permission for location then after just wait for few seconds,GPS will take time for stable location ,after that we will get the actual values of lat and long.
Setting -> GPS Enable
Reason for lat long value comes 0.0
Here is what you want..!
also check this is one of the reason. Go to maps default application and allow user to allow latitude and longitude option .In our application When the GPS signal blinks and when it stops we will get the latitude and longitude. This Worked for me
Edit 1
Open Google Maps app and click button on map to get current location.
When you allow Google map permission, then only other apps permission will work. (and I feel this is big bug)
Now go to your app and try to get current location and it will work.
This is ugly, but we have follow those steps to get current location in our app.