本文整理汇总了Java中com.google.android.gms.location.GeofencingRequest类的典型用法代码示例。如果您正苦于以下问题:Java GeofencingRequest类的具体用法?Java GeofencingRequest怎么用?Java GeofencingRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GeofencingRequest类属于com.google.android.gms.location包,在下文中一共展示了GeofencingRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: addGeofence
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private void addGeofence() {
final GeofencingRequest geofencingRequest = createGeofencingRequest();
if (geofencingRequest == null) return;
final PendingIntent pendingIntent = createNotificationBroadcastPendingIntent();
reactiveLocationProvider
.removeGeofences(pendingIntent)
.flatMap(new Func1<Status, Observable<Status>>() {
@Override
public Observable<Status> call(Status pendingIntentRemoveGeofenceResult) {
return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest);
}
})
.subscribe(new Action1<Status>() {
@Override
public void call(Status addGeofenceResult) {
toast("Geofence added, success: " + addGeofenceResult.isSuccess());
}
}, new Action1<Throwable>() {
@Override
public void call(Throwable throwable) {
toast("Error adding geofence.");
Log.d(TAG, "Error adding geofence.", throwable);
}
});
}
示例2: createGeofencingRequest
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private GeofencingRequest createGeofencingRequest() {
try {
double longitude = Double.parseDouble(longitudeInput.getText().toString());
double latitude = Double.parseDouble(latitudeInput.getText().toString());
float radius = Float.parseFloat(radiusInput.getText().toString());
Geofence geofence = new Geofence.Builder()
.setRequestId("GEOFENCE")
.setCircularRegion(latitude, longitude, radius)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
.build();
return new GeofencingRequest.Builder().addGeofence(geofence).build();
} catch (NumberFormatException ex) {
toast("Error parsing input.");
return null;
}
}
示例3: getGeofencingRequest
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private GeofencingRequest getGeofencingRequest() {
if (this.place == null || this.place.getLocation() == null) {
return null;
}
// called when the transition associated with the Geofence is triggered)
List<Geofence> geoFenceList = new ArrayList<Geofence>();
geoFenceList.add(new Geofence.Builder()
.setRequestId(GEOFENCE_REQUEST_ID)
.setCircularRegion(this.place.getLocation().getLatitude(),
this.place.getLocation().getLongitude(),
GEOFENCE_RADIUS_IN_METERS
)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_DWELL | Geofence.GEOFENCE_TRANSITION_ENTER)
.setLoiteringDelay(LOITERING_DELAY_MS)
.setNotificationResponsiveness(NOTIFICATION_RESPONSIVENESS_MS)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.build());
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER | GeofencingRequest.INITIAL_TRIGGER_DWELL);
builder.addGeofences(geoFenceList);
return builder.build();
}
示例4: startInternal
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private void startInternal(final Location homeLocation, PendingIntent pendingIntent) {
GeofencingRequest geofenceRequest = createGeofenceRequest(homeLocation);
if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
ToastLog.logShort(context, TAG, "Starting Play geofencing...");
LocationServices.GeofencingApi.addGeofences(
googleApiClient,
geofenceRequest,
pendingIntent
).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.getStatusMessage() != null) {
ToastLog.warnShort(context, TAG, status.getStatusMessage());
}
}
});
}
}
示例5: addGeofence
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private void addGeofence(PendingIntent pendingIntent, GeofencingRequest geofencingRequest) {
if (!mGeofencingRequestsMap.containsKey(pendingIntent)) {
mGeofencingRequestsMap.put(pendingIntent, geofencingRequest);
if (mGoogleApiClient.isConnected()) {
if (!isLocationUpdates) {
// requestLocationUpdates for getting current position
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
isLocationUpdates = true;
}
LocationServices.GeofencingApi.addGeofences(
mGoogleApiClient,
geofencingRequest,
pendingIntent
).setResultCallback(this);
}
}
}
示例6: onConnected
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
@Override
public void onConnected(@Nullable Bundle bundle) {
Log.i(TAG, "Connected to GoogleApiClient");
try {
// requestLocationUpdates for getting current position
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
isLocationUpdates = true;
for (Map.Entry<PendingIntent, GeofencingRequest> entry :
mGeofencingRequestsMap.entrySet()) {
addGeofence(entry.getKey(), entry.getValue());
}
} catch (SecurityException securityException) {
// Catch exception generated if the app does not use ACCESS_FINE_LOCATION permission.
showSecurityException(securityException);
}
}
示例7: add
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
public void add(GMap.Location location, ResultCallback callback){
Log.i(TAG, "add " + location.toString());
String id = location.url.toString()+"\t"+location.name;
Geofence fence = new Geofence.Builder()
.setRequestId(id)
.setCircularRegion( // 500メートル以内
location.latitude, location.longitude, 500)
.setExpirationDuration( // 期限を指定できる
Geofence.NEVER_EXPIRE)
.setTransitionTypes(
Geofence.GEOFENCE_TRANSITION_ENTER)
.build();
GeofencingRequest request = new GeofencingRequest.Builder()
.addGeofence(fence) // Geofenceを1つ登録
.build();
// IntentServiceで受け取る
Intent intent = new Intent(context, GeofenceReceiveService.class);
PendingIntent pIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
LocationServices.GeofencingApi
.addGeofences(client, request, pIntent)
.setResultCallback(callback);
}
示例8: registerGeofence
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
@SuppressWarnings("ResourceType")
private void registerGeofence() {
orchextraLogger.log("Removing " + geofenceUpdates.getDeleteGeofences().size() + " geofences...");
orchextraLogger.log("Registering " + geofenceUpdates.getNewGeofences().size() + " geofences...");
List<String> deleteCodeList = androidGeofenceConverter.getCodeList(geofenceUpdates.getDeleteGeofences());
if (deleteCodeList.size() > 0) {
LocationServices.GeofencingApi.removeGeofences(googleApiClientConnector.getGoogleApiClient(), deleteCodeList);
}
if (geofenceUpdates.getNewGeofences().size() > 0) {
GeofencingRequest geofencingRequest =
androidGeofenceConverter.convertGeofencesToGeofencingRequest(geofenceUpdates.getNewGeofences());
if (googleApiClientConnector.isGoogleApiClientAvailable()) {
try {
LocationServices.GeofencingApi.addGeofences(googleApiClientConnector.getGoogleApiClient(), geofencingRequest,
geofencePendingIntentCreator.getGeofencingPendingIntent()).setResultCallback(this);
}catch (Exception e){
orchextraLogger.log("Exception trying to add geofences: " + e.getMessage(),
OrchextraSDKLogLevel.ERROR);
}
}
}
}
示例9: addGeofence
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
private void addGeofence(GeofencingRequest geofencingRequest,
PendingIntent geofencePendingIntent) {
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager
.PERMISSION_GRANTED) {
return;
}
LocationServices.GeofencingApi.addGeofences(
googleApiClient,
geofencingRequest,
geofencePendingIntent
).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
switch (status.getStatusCode()) {
case CommonStatusCodes.SUCCESS:
StatusMessageHandler.showInfoMessage(context, R.string.geofence_enabled, Snackbar.LENGTH_SHORT);
}
Log.d(GeofenceApiHandler.class, status.toString());
}
});
}
示例10: onConnected
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
@Override
public void onConnected(Bundle connectionHint) {
// We're connected, now we need to create a GeofencingRequest with
// the geofences we have stored.
mGeofencingRequest = new GeofencingRequest.Builder().addGeofences(
mGeofences).build();
//mGeofencingRequest = new getGeofencingRequest().Builder();
mPendingIntent = createRequestPendingIntent();
// This is for debugging only and does not affect
// geofencing.
LocationServices.FusedLocationApi.requestLocationUpdates(
mGoogleApiClient, mLocationRequest, this);
// Submitting the request to monitor geofences.
PendingResult<Status> pendingResult = LocationServices.GeofencingApi
.addGeofences(mGoogleApiClient, getGeofencingRequest(),
mPendingIntent);
// Set the result callbacks listener to this class.
pendingResult.setResultCallback(this);
}
示例11: onConnected
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
@Override
public void onConnected(Bundle bundle) {
// Now we can do the actual logic
List<Geofence> fences = new ArrayList<Geofence>();
fences.add(fence.toGeofence(venue));
geofencingapi = LocationServices.GeofencingApi;
if(locationClient != null && locationClient.isConnected() && fences.size() > 0){
GeofencingRequest request = new GeofencingRequest.Builder()
.addGeofences(fences)
.build();
PendingResult<Status> status = geofencingapi.addGeofences(locationClient, request, geofenceUtils.getTransitionPendingIntent(this));
status.setResultCallback(this, 10, TimeUnit.SECONDS);
// disconnect will be done in resultlistener
}else if(locationClient != null && locationClient.isConnected()){
locationClient.disconnect();
}
}
示例12: location_geofencesCreateTriggerRequest
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
/**
* Creates a geofencing trigger request. This will make the location service
* to launch geofencing events (enter/exit events) with the specified
* geofence list.
* <br>
* See Geofences at <a href="http://developer.android.com/intl/es/training/location/geofencing.html">Google developer</a>.
* <br><br>
* Note:<br><br>
*
* Requires the permission {@link android.permission.ACCESS_FINE_LOCATION}.
*
* @param geofenceList The list of Geofences to watch.
*/
public static GeofencingRequest location_geofencesCreateTriggerRequest(List<Geofence> geofenceList) {
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
//The GEOFENCE_TRANSITION_ENTER/GEOFENCE_TRANSITION_EXIT transition
//triggers when a device enters/exits a geofence.
//
//Specifying INITIAL_TRIGGER_ENTER tells Location services that
//GEOFENCE_TRANSITION_ENTER should be triggered if the the device is
//already inside the geofence.
//
//In many cases, it may be preferable to use instead INITIAL_TRIGGER_DWELL,
//which triggers events only when the user stops for a defined duration
//within a geofence.
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofences(geofenceList);
return builder.build();
}
示例13: settingGeofence
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
public GeofencingRequest settingGeofence(AlarmRealmData data) {
Geofence geofence = new Geofence.Builder()
.setRequestId(data.getGeofenceId())
.setCircularRegion(mTargetLocation.latitude, mTargetLocation.longitude, GEOFENCE_CIRCLE_RADIUS)
.setExpirationDuration(Geofence.NEVER_EXPIRE)
.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
.build();
GeofencingRequest request = new GeofencingRequest.Builder()
.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER )
.addGeofence(geofence)
.build();
return request;
}
示例14: getGeofenceRequest
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
/***
* creates a {@link GeofencingRequest} request object using the mGeofenceList , Arraylist of geofences.
* Used by {@link #registerAllGeofences()}
*
* @return the GeofencingRequest object.
*/
private GeofencingRequest getGeofenceRequest(){
GeofencingRequest.Builder builder = new GeofencingRequest.Builder();
builder.setInitialTrigger(GeofencingRequest.INITIAL_TRIGGER_ENTER);
builder.addGeofences(mGeofenceList);
return builder.build();
}
示例15: getGeofencingRequest
import com.google.android.gms.location.GeofencingRequest; //导入依赖的package包/类
public static GeofencingRequest getGeofencingRequest(Context context) {
String geofencingRequestJSON = getSharedPreferences(context).getString(GEOFENCING_REQUEST, null);
if (geofencingRequestJSON == null) {
return null;
}
Gson gson = new Gson();
Type type = new TypeToken<GeofencingRequest>() {
}.getType();
return gson.fromJson(geofencingRequestJSON, type);
}