get the current loacation (gps/wifi)

Posted by gilmad on Stack Overflow See other posts from Stack Overflow or by gilmad
Published on 2010-04-23T14:13:12Z Indexed on 2010/04/23 14:23 UTC
Read the original article Hit count: 230

Filed under:
|

i'm trying to get my location using it like this:

LocationManager myLocationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);

         Criteria criteria = new Criteria(); 
         criteria.setAccuracy(Criteria.ACCURACY_FINE); 
         criteria.setAltitudeRequired(false); 
         criteria.setBearingRequired(false); 
         criteria.setCostAllowed(true); 
         criteria.setPowerRequirement(Criteria.POWER_LOW); 

         String provider = myLocationManager.getBestProvider(criteria,true); 

         if (provider != null) { 
            //there is a provider
             myLocationManager.requestLocationUpdates(provider, 10L, 500.0f, (LocationListener) mainContext);
             Location myCurLocation = myLocationManager.getLastKnownLocation(provider); 
            //here i'm trying to get some data from the
            //myCurLocation but 
            //myCurLocation == NULL
         }

but the myCurLocation is always == NULL what am I doing wrong??

© Stack Overflow or respective owner

Related posts about android

Related posts about location