Getting 0.0 for latitude and longitude while showing current location in map

tejas picture tejas · Oct 4, 2011 · Viewed 29.2k times · Source

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

Answer

Pradeep picture Pradeep · Nov 16, 2011

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

  1. Open Google Maps app and click button on map to get current location.

  2. When you allow Google map permission, then only other apps permission will work. (and I feel this is big bug)

  3. 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.