- GPS Provider
- Network Provider
and back to GPS Provider.
we have to create LocationManager and LocationListener and don't forget to check the permission.
LocationManager:
LocationManager locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener:
LocationListener locationListener = new MyGPS();
MyGPS class is my personal class that implements Location Listener then in that class I overide methods..
@Overridepublic void onLocationChanged(Location loc) { String longitude = "Longitude: " + loc.getLongitude(); String latitude = "Latitude: " + loc.getLatitude(); }
Check the permission:
int permissionCheck = ContextCompat.checkSelfPermission(MapsActivity.this,
Manifest.permission.ACCESS_FINE_LOCATION);
and set Location Request Updates:
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 500, 1, locationListener);
500 is long type value of minimum time to update. and
1 is float type value of minimum distance to update.
and to get the location we can access it by:
Location locationGPS = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
then we can access the Network Location Provider Latitude and Longitude with
locationGPS.getLatitude();
andlocationGPS.getLongitude();
with double value type as return.
okay done for Location Provider with GPS Provider
have a very nice try friend. ^__^.
"The biggest failure in life is to die without ever tried"
No comments:
Post a Comment