Hi!
By using Device we can track the user by their lastknown loc (LKN).
Method To Call The LKN
By using Device we can track the user by their lastknown loc (LKN).
Method To Call The LKN
private Location getLastBestLocation() {
// get the locationmanager
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
// get the status of GPS
Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
// get the status of Provider Location locationNet = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); long GPSLocationTime = 0; if (null != locationGPS) { GPSLocationTime = locationGPS.getTime(); } long NetLocationTime = 0; if (null != locationNet) { NetLocationTime = locationNet.getTime(); } if (0 < GPSLocationTime - NetLocationTime) { return locationGPS; } else { return locationNet; } }
// Convert the LKL as ADS
Location location = getLastBestLocation(); if (location != null) { latu = location.getLatitude(); lngu = location.getLongitude(); Geocoder geocoder; List<Address> addresses; geocoder = new Geocoder(PO_Entry.this, Locale.getDefault()); try { addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1); String address = addresses.get(0).getAddressLine(0); String city = addresses.get(0).getLocality(); String state = addresses.get(0).getAdminArea(); String country = addresses.get(0).getCountryName(); String postalCode = addresses.get(0).getPostalCode(); String knownName = addresses.get(0).getFeatureName(); et_po_enty_loc.setText(address + " , " + city + "\n" + state + " , " + country + " , " + postalCode); } catch (IOException e) { e.printStackTrace(); } } else { et_po_enty_loc.setText("No Location Found"); }Thank You!Please Leave Your Comment..,
Have A Happy Day..,
No comments:
Post a Comment