当前位置: 首页>>代码示例>>Java>>正文


Java Geofence类代码示例

本文整理汇总了Java中com.google.android.gms.location.Geofence的典型用法代码示例。如果您正苦于以下问题:Java Geofence类的具体用法?Java Geofence怎么用?Java Geofence使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Geofence类属于com.google.android.gms.location包,在下文中一共展示了Geofence类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: GeofencingController

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
public GeofencingController(Context context) {
    this.context = context;

    // Empty list for storing geofences.
    mGeofenceList = new ArrayList<Geofence>();

    // Initially set the PendingIntent used in addGeofences() and removeGeofences() to null.
    mGeofencePendingIntent = null;

    // Retrieve an instance of the SharedPreferences object.
    mSharedPreferences = context.getSharedPreferences(Constants.SHARED_PREFERENCES_NAME,
            MODE_PRIVATE);

    // Get the value of mGeofencesAdded from SharedPreferences. Set to false as a default.
    mGeofencesAdded = mSharedPreferences.getBoolean(Constants.GEOFENCES_ADDED_KEY, false);

    // Kick off the request to build GoogleApiClient.
    buildGoogleApiClient();
}
 
开发者ID:RobinCaroff,项目名称:MyGeofencer,代码行数:20,代码来源:GeofencingController.java

示例2: getGeofenceTransitionDetails

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
/**
 * Gets transition details and returns them as a formatted string.
 *
 * @param context               The app context.
 * @param geofenceTransition    The ID of the geofence transition.
 * @param triggeringGeofences   The geofence(s) triggered.
 * @return                      The transition details formatted as String.
 */
private String getGeofenceTransitionDetails(
        Context context,
        int geofenceTransition,
        List<Geofence> triggeringGeofences) {

    String geofenceTransitionString = getTransitionString(geofenceTransition);

    // Get the Ids of each geofence that was triggered.
    ArrayList triggeringGeofencesIdsList = new ArrayList();
    for (Geofence geofence : triggeringGeofences) {
        triggeringGeofencesIdsList.add(geofence.getRequestId());
    }
    String triggeringGeofencesIdsString = TextUtils.join(", ",  triggeringGeofencesIdsList);

    return geofenceTransitionString + ": " + triggeringGeofencesIdsString;
}
 
开发者ID:RobinCaroff,项目名称:MyGeofencer,代码行数:25,代码来源:GeofenceTransitionsIntentService.java

示例3: createGeofencingRequest

import com.google.android.gms.location.Geofence; //导入依赖的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;
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:GeofenceActivity.java

示例4: updateGeofencesList

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
/**
 * Updates the local {@link ArrayList} of geofences from the data in the passed list
 *Uses the place id defined by the API as the geofence object id.
 *
 * @param places the placeBuffer result of the getPlaceByid call.
 */
public void updateGeofencesList(PlaceBuffer places){
    mGeofenceList = new ArrayList<>();
    if (places==null || places.getCount()==0) return;
    for (Place place: places){
        String placeUid = place.getId();
        double latitude = place.getLatLng().latitude;
        double longitude = place.getLatLng().longitude;
        //Build a geofence object
        Geofence geofence = new Geofence.Builder()
                .setRequestId(placeUid)
                .setExpirationDuration(GEOFENCE_TIMEOUT)
                .setCircularRegion(latitude,longitude,GEOFENCE_RADIUS)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
                .build();
        mGeofenceList.add(geofence);
    }
}
 
开发者ID:samagra14,项目名称:Shush,代码行数:24,代码来源:Geofencing.java

示例5: getGeofencingRequest

import com.google.android.gms.location.Geofence; //导入依赖的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();
}
 
开发者ID:hypertrack,项目名称:hypertrack-live-android,代码行数:25,代码来源:ActionManager.java

示例6: geofenceFromMap

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
private Geofence geofenceFromMap(Map<String, Object> regionData, String regionName) {
  Number latitude = (Number) regionData.get("lat");
  Number longitude = (Number) regionData.get("lon");
  Number radius = (Number) regionData.get("radius");
  Number version = (Number) regionData.get("version");
  if (latitude == null) {
    return null;
  }
  Builder geofenceBuilder = new Builder();
  geofenceBuilder.setCircularRegion(latitude.floatValue(),
      longitude.floatValue(), radius.floatValue());
  geofenceBuilder.setRequestId(geofenceID(regionName, version.intValue()));
  geofenceBuilder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
      Geofence.GEOFENCE_TRANSITION_EXIT);
  geofenceBuilder.setExpirationDuration(Geofence.NEVER_EXPIRE);
  return geofenceBuilder.build();
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:18,代码来源:LocationManagerImplementation.java

示例7: onHandleIntent

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
  try {
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.hasError()) {
      int errorCode = event.getErrorCode();
      Log.d("Location Client Error with code: " + errorCode);
    } else {
      int transitionType = event.getGeofenceTransition();
      List<Geofence> triggeredGeofences = event.getTriggeringGeofences();
      if (transitionType == Geofence.GEOFENCE_TRANSITION_ENTER ||
          transitionType == Geofence.GEOFENCE_TRANSITION_EXIT) {
        LocationManagerImplementation locationManager = (LocationManagerImplementation)
            ActionManager.getLocationManager();
        if (locationManager != null) {
          locationManager.updateStatusForGeofences(triggeredGeofences, transitionType);
        }
      }
    }
  } catch (Throwable t) {
    Util.handleException(t);
  }
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:24,代码来源:ReceiveTransitionsIntentService.java

示例8: handleLogTransition

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
private void handleLogTransition(int geofenceTransition) {

        String transitionStr = "";
        switch (geofenceTransition) {
            case Geofence.GEOFENCE_TRANSITION_ENTER:
                transitionStr = "GEOFENCE_TRANSITION_ENTER";
                break;
            case Geofence.GEOFENCE_TRANSITION_EXIT:
                transitionStr = "GEOFENCE_TRANSITION_EXIT";
                break;
            case Geofence.GEOFENCE_TRANSITION_DWELL:
                transitionStr = "GEOFENCE_TRANSITION_DWELL";
                break;
        }
        Log.d(TAG, transitionStr + " detected! ");
    }
 
开发者ID:abicelis,项目名称:Remindy,代码行数:17,代码来源:GeofenceNotificationIntentService.java

示例9: getGeofenceList

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
private static List<Geofence> getGeofenceList(List<Place> places) {
    List<Geofence> geofenceList = new ArrayList<>();

    for (Place place : places){
        geofenceList.add(new Geofence.Builder()
                // Set the request ID of the geofence. This is a string to identify this
                // geofence.
                .setRequestId(String.valueOf(place.getId()))
                .setCircularRegion(
                        place.getLatitude(),
                        place.getLongitude(),
                        place.getRadius()
                )
                .setExpirationDuration(NEVER_EXPIRE)
                .setLoiteringDelay(LOITERING_DWELL_DELAY)
                .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT | Geofence.GEOFENCE_TRANSITION_DWELL)
                //.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_EXIT | Geofence.GEOFENCE_TRANSITION_DWELL)
                .build());
    }

    return geofenceList;
}
 
开发者ID:abicelis,项目名称:Remindy,代码行数:23,代码来源:GeofenceUtil.java

示例10: onHandleIntent

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    GeofencingEvent fenceEvent = GeofencingEvent.fromIntent(intent);
    if (fenceEvent.hasError()) {
        String errorMessage = GeofenceStatusCodes.getStatusCodeString(fenceEvent.getErrorCode());
        Timber.i(errorMessage);
        return;
    }
    Timber.i("We got a geofence intent");

    if (fenceEvent.getGeofenceTransition() != Geofence.GEOFENCE_TRANSITION_DWELL
            || fenceEvent.getTriggeringGeofences().isEmpty()) {
        return;
    }

    String placeId = fenceEvent.getTriggeringGeofences().get(0).getRequestId();
    Realm realm = Realm.getDefaultInstance();
    Place place = Place.findFirst(realm, placeId);
    String title = place != null ?
            getString(R.string.geofence_notification_place_title, place.getName()) :
            getString(R.string.geofence_notification_title);
    String content = getString(R.string.geofence_notification_content);
    String imageUrl = place != null ? place.getFirstImage(GEOFENCE_LARGE_ICON_SIZE) : null;
    realm.close();
    sendNotification(title, content, placeId, imageUrl);
}
 
开发者ID:Turistforeningen,项目名称:SjekkUT,代码行数:27,代码来源:GeofenceIntentService.java

示例11: getTransitionDetails

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
/**
 * Concatenates all the id's to one String
 * @param context from which a call is being made
 * @param geofenceTransition type of transition
 * @param triggeringGeofences list of all triggering transitions
 * @return list of Strings with the type of a transition and all triggering id's
 */
public static List<String> getTransitionDetails(Context context,
                                                int geofenceTransition,
                                                List<Geofence> triggeringGeofences) {

    String geofenceTransitionString = getTransitionString(context, geofenceTransition);

    // Get the Ids of each geofence that was triggered.
    List<String> triggeringGeofencesIdsList = new ArrayList<>();
    triggeringGeofencesIdsList.add(geofenceTransitionString);

    for (Geofence geofence : triggeringGeofences) {
        triggeringGeofencesIdsList.add(geofence.getRequestId());
    }

    return triggeringGeofencesIdsList;
}
 
开发者ID:dmytroKarataiev,项目名称:EarthquakeSurvival,代码行数:24,代码来源:LocationUtils.java

示例12: onReceive

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
@Override
public void onReceive(Context context, Intent intent) {
    GeofencingEvent event = GeofencingEvent.fromIntent(intent);
    if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER)
        Log.d("aken-ajalukku", "Entered geofence!");
    else
        Log.d("aken-ajalukku", "Exited geofence!");
    if (event.getGeofenceTransition() == Geofence.GEOFENCE_TRANSITION_ENTER) {
        List<Geofence> geofences = event.getTriggeringGeofences();
        ArrayList<PointOfInterest> pois = new ArrayList<>();
        for (Geofence gf : geofences) {
            pois.add(Data.instance.getPoiById(Integer.parseInt(gf.getRequestId())));
        }
        createNotification(context, pois);
    }
}
 
开发者ID:rasmussaks,项目名称:aken-ajalukku,代码行数:17,代码来源:GeofenceTransitionsReceiver.java

示例13: populateGeofencesList

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
private void populateGeofencesList() {
    geofences = new ArrayList<>();
    for (PointOfInterest poi : Data.instance.getPois()) {
        geofences.add(
                new Geofence.Builder()
                        .setRequestId(String.valueOf(poi.getId()))
                        .setCircularRegion(poi.getLocation().latitude,
                                poi.getLocation().longitude,
                                GEOFENCE_RADIUS_IN_METERS)
                        .setExpirationDuration(GEOFENCE_EXPIRATION_IN_MILLISECONDS)
                        .setNotificationResponsiveness(GEOFENCE_RESPONSIVENESS_IN_MILLISECONDS)
                        .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT)
                        .build()
        );
    }
}
 
开发者ID:rasmussaks,项目名称:aken-ajalukku,代码行数:17,代码来源:GeofenceManager.java

示例14: toGeofence

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
public Geofence toGeofence(Date expiryDate) {
    Long expirationDurationMillis = 0L;
    if (expiryDate != null) {
        expirationDurationMillis = expiryDate.getTime() - Time.now();
    }
    if (expirationDurationMillis <= 0) {
        expirationDurationMillis = Geofence.NEVER_EXPIRE;
    }

    return new Geofence.Builder()
            .setCircularRegion(getLatitude(), getLongitude(), getRadius())
            .setRequestId(getId())
            .setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
            .setExpirationDuration(expirationDurationMillis)
            .build();
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:17,代码来源:Area.java

示例15: shouldCalculateRefreshDatesForGeoStartAndExpired

import com.google.android.gms.location.Geofence; //导入依赖的package包/类
@Test
public void shouldCalculateRefreshDatesForGeoStartAndExpired() throws Exception {
    // Given
    Long millis15MinAfterNow = now + 15 * 60 * 1000;
    Long millis30MinAfterNow = now + 30 * 60 * 1000;
    String date15MinAfterNow = DateTimeUtil.ISO8601DateToString(new Date(millis15MinAfterNow));
    String date30MinAfterNow = DateTimeUtil.ISO8601DateToString(new Date(millis30MinAfterNow));

    saveGeoMessageToDb(date15MinAfterNow, date30MinAfterNow);

    // When
    Pair<List<Geofence>, Pair<Date, Date>> geofencesAndNextRefreshDate = geofencingImpl.calculateGeofencesToMonitorDates(geoStore);

    // Then
    assertNotNull(geofencesAndNextRefreshDate);
    assertTrue(geofencesAndNextRefreshDate.first.isEmpty());
    assertNotNull(geofencesAndNextRefreshDate.second);

    Date refreshStartDate = geofencesAndNextRefreshDate.second.first;
    Date refreshExpiryDate = geofencesAndNextRefreshDate.second.second;
    assertEquals(millis15MinAfterNow, refreshStartDate.getTime(), 3000);
    assertEquals(millis30MinAfterNow, refreshExpiryDate.getTime(), 3000);
}
 
开发者ID:infobip,项目名称:mobile-messaging-sdk-android,代码行数:24,代码来源:GeofencingTest.java


注:本文中的com.google.android.gms.location.Geofence类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。