Code example for LocationManager: Getting continuous location updates

Methods: addTestProviderrequestLocationUpdatessetTestProviderEnabledsetTestProviderLocationsetTestProviderStatus

0
    } 
 
	private void doIt () 
    { 
 
    	lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, new LocationListener() {       
    	            @Override 
    	            public void onStatusChanged(String provider, int status, Bundle extras) {}
    	            @Override 
    	            public void onProviderEnabled(String provider) {}
    	            @Override 
    	            public void onProviderDisabled(String provider) {}
    	            @Override 
    	            public void onLocationChanged(Location location) {}
    	}); 
    	             
    	/* Set a mock location for debugging purposes */ 
    	setMockLocation(15.387653, 73.872585, 500); 
    } 
     
    private void setMockLocation(double latitude, double longitude, float accuracy) {
    	 
        lm.addTestProvider (LocationManager.GPS_PROVIDER,
                            "requiresNetwork" == "", 
                            "requiresSatellite" == "", 
                            "requiresCell" == "", 
                            "hasMonetaryCost" == "", 
                            "supportsAltitude" == "", 
                            "supportsSpeed" == "", 
                            "supportsBearing" == "", 
                             android.location.Criteria.POWER_LOW,
                             android.location.Criteria.ACCURACY_FINE);      
 
        Location newLocation = new Location(LocationManager.GPS_PROVIDER);
 
        newLocation.setLatitude(latitude);
        newLocation.setLongitude(longitude);
        newLocation.setAccuracy(accuracy);
 
        lm.setTestProviderEnabled(LocationManager.GPS_PROVIDER, true);
 
        lm.setTestProviderStatus(LocationManager.GPS_PROVIDER,
                                 LocationProvider.AVAILABLE,
                                 null,System.currentTimeMillis());    
       
        lm.setTestProviderLocation(LocationManager.GPS_PROVIDER, newLocation);      
 
    } 
 
}