The problem is that you need a LocationRequest to track your geospatial location ...
If you use Google maps at the same time. Your geofence monitoring will work! because google maps make LocationRequest and geofence visible ...
Then, if you need to be autonomous in monitoring geofence, you need to make a LocationRequest handler ...
Google Api LocationRequest
Code example
FusedLocationProviderClient fusedLocationProviderClient = new FusedLocationProviderClient(activity); fusedLocationProviderClient.requestLocationUpdates(getLocationRequest(), getPendingIntent()); private LocationRequest getLocationRequest() { LocationRequest mLocationRequest = new LocationRequest(); mLocationRequest.setInterval(10000); mLocationRequest.setFastestInterval(5000); mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY); return mLocationRequest; } private PendingIntent getPendingIntent() { // Reuse the PendingIntent if we already have it. Log.e(TAG, "Creating Monitoring Geofence..."); if (mGeofencePendingIntent != null) { return mGeofencePendingIntent; } Intent intent = new Intent(activity, LocationService.class); // We use FLAG_UPDATE_CURRENT so that we get the same pending intent back when // calling addGeofencesTask() and removeGeofences(). mGeofencePendingIntent = PendingIntent.getService(activity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); return mGeofencePendingIntent; }
In this code, you take a location request after 10 seconds ... And tracking the geofence every 10 seconds of the geofence ...
source share