Code example for LocationManager: Getting continuous location updates

Methods: isProviderEnabledrequestLocationUpdates

0
        locationResult=result;
        if(lm==null)
            lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
 
        //exceptions will be thrown if provider is not permitted. 
        try{gps_enabled=lm.isProviderEnabled(LocationManager.GPS_PROVIDER);}catch(Exception ex){}
        try{network_enabled=lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);}catch(Exception ex){}
 
        //don't start listeners if no provider is enabled 
        if(!gps_enabled && !network_enabled) {
        	Toast.makeText(context, "No location provider available, defaulting to Gates Building, Stanford Univesity.", Toast.LENGTH_SHORT).show();
        	Location l = new Location("yo' mama");
        	l.setLongitude(-122.179727);
        	l.setLatitude(37.426762);
        	locationResult.gotLocation(l);
            return false; 
        } 
 
        if(gps_enabled)
            lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListenerGps);
        if(network_enabled)
            lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, locationListenerNetwork);
        timer1=new Timer();
        timer1.schedule(new GetLastLocation(), 20000);
        return true; 
    } 
 
Stop searching for code, let great code find you!  Add Codota to your java IDE