private void getLocation() { Location gpslocation = null; Location networkLocation = null;
if(locationManager==null){ locationManager = (LocationManager) getApplicationContext() .getSystemService(Context.LOCATION_SERVICE); } try { if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)){ locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,100, 0, locationListener); gpslocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); Log.v(“Which provider Enabled:”, “GPS”); } if(locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)){ locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,100, 0, locationListener); networkLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Log.v(“Which provider Enabled:”, “Network”); } } catch (IllegalArgumentException e) { Log.e(“error”, e.toString()); } if(gpslocation==null && networkLocation==null) { location1= null; Log.v(“Provider value:”, “G and N both Null”); }
if(gpslocation!=null && networkLocation!=null){ if(gpslocation.getTime() < networkLocation.getTime()){ gpslocation = null; location1= networkLocation; Log.v(“Provider value:”, “G is less active N return”); }else{ networkLocation = null; location1= gpslocation; Log.v(“Provider value:”, “N is less active G return”); } } if (gpslocation == null) { location1= networkLocation; Log.v(“Provider value:”, “G is Null N return”); } if (networkLocation == null) { location1= gpslocation; Log.v(“Provider value:”, “N is Null G return”); } location1= null; }
it gives the location..