Code example for LocationManager: Finding current location

Methods: getLastKnownLocationrequestSingleUpdate

0
		locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		String providerStr = LocationManager.NETWORK_PROVIDER;//nie trzeba odswiezac samemu, zzera mniej baterii niz gps
		//String providerStr = LocationManager.PASSIVE_PROVIDER; 
		int a=0;
		 
		locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, PendingIntent.getService(getApplicationContext(), a, getIntent(), a));
		locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, PendingIntent.getService(getApplicationContext(), a, getIntent(), a));
		//to wyzej dwa razy, bo czasami nie odswieza od razu 
		Location location = locationManager.getLastKnownLocation(providerStr);
		//location.set(new Location(providerStr)); 
		//locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, PendingIntent.getService(getApplicationContext(), a, getIntent(), a)); 
		//location = locationManager.getLastKnownLocation(providerStr); 
		double latitude = location.getLatitude();//n-s
		double longitude = location.getLongitude();//e-w
		 
		//location.getSpeed();//predkosc 
		//location.toString(); 
		//Toast.makeText(getApplicationContext(), location.getProvider(),  Toast.LENGTH_SHORT).show(); 
		//TextView text = (TextView) findViewById(R.id.textGPS); 
    	//text.setText(location.toString());