示例#1
0
        public void CreateGeofences()
        {
            // Create internal "flattened" objects containing the geofence data
            mAndroidBuildingGeofence = new SimpleGeofence(
                Constants.ANDROID_BUILDING_ID,                 // geofenceId
                Constants.ANDROID_BUILDING_LATITUDE,
                Constants.ANDROID_BUILDING_LONGITUDE,
                Constants.ANDROID_BUILDING_RADIUS_METERS,
                Constants.GEOFENCE_EXPIRATION_TIME,
                Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit
                );
            mYerbaBuenaGeofence = new SimpleGeofence(
                Constants.YERBA_BUENA_ID,                 // geofenceId
                Constants.YERBA_BUENA_LATITUDE,
                Constants.YERBA_BUENA_LONGITUDE,
                Constants.YERBA_BUENA_RADIUS_METERS,
                Constants.GEOFENCE_EXPIRATION_TIME,
                Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit
                );

            // Store these flat versions in SharedPreferences and add them to the geofence list
            mGeofenceStorage.SetGeofence(Constants.ANDROID_BUILDING_ID, mAndroidBuildingGeofence);
            mGeofenceStorage.SetGeofence(Constants.YERBA_BUENA_ID, mYerbaBuenaGeofence);
            mGeofenceList.Add(mAndroidBuildingGeofence.ToGeofence());
            mGeofenceList.Add(mYerbaBuenaGeofence.ToGeofence());
        }
		/// <summary>
		/// Save a geofence
		/// </summary>
		/// <param name="id">The ID of the Geofence</param>
		/// <param name="geofence">The SimpleGeofence with the values you want to save in SharedPreferemces</param>
		public void SetGeofence(String id, SimpleGeofence geofence) {
			// Get a SharedPreferences editor instance. Among other things, SharedPreferences ensures that updates are atomic and non-concurrent
			ISharedPreferencesEditor prefs = mPrefs.Edit();
			// Write the geofence values to SharedPreferences 
			prefs.PutFloat(GetGeofenceFieldKey(id, Constants.KEY_LATITUDE), (float) geofence.Latitude);
			prefs.PutFloat(GetGeofenceFieldKey(id, Constants.KEY_LONGITUDE), (float) geofence.Longitude);
			prefs.PutFloat (GetGeofenceFieldKey (id, Constants.KEY_RADIUS), geofence.Radius);
			prefs.PutLong (GetGeofenceFieldKey (id, Constants.KEY_EXPIRATION_DURATION), geofence.ExpirationDuration);
			prefs.PutInt (GetGeofenceFieldKey (id, Constants.KEY_TRANSITION_TYPE), geofence.TransitionType);
			// Commit the changes
			prefs.Commit ();
		}
        /// <summary>
        /// Save a geofence
        /// </summary>
        /// <param name="id">The ID of the Geofence</param>
        /// <param name="geofence">The SimpleGeofence with the values you want to save in SharedPreferemces</param>
        public void SetGeofence(String id, SimpleGeofence geofence)
        {
            // Get a SharedPreferences editor instance. Among other things, SharedPreferences ensures that updates are atomic and non-concurrent
            ISharedPreferencesEditor prefs = mPrefs.Edit();

            // Write the geofence values to SharedPreferences
            prefs.PutFloat(GetGeofenceFieldKey(id, Constants.KEY_LATITUDE), (float)geofence.Latitude);
            prefs.PutFloat(GetGeofenceFieldKey(id, Constants.KEY_LONGITUDE), (float)geofence.Longitude);
            prefs.PutFloat(GetGeofenceFieldKey(id, Constants.KEY_RADIUS), geofence.Radius);
            prefs.PutLong(GetGeofenceFieldKey(id, Constants.KEY_EXPIRATION_DURATION), geofence.ExpirationDuration);
            prefs.PutInt(GetGeofenceFieldKey(id, Constants.KEY_TRANSITION_TYPE), geofence.TransitionType);
            // Commit the changes
            prefs.Commit();
        }
示例#4
0
		public void CreateGeofences ()
		{
			// Create internal "flattened" objects containing the geofence data
			mAndroidBuildingGeofence = new SimpleGeofence (
				Constants.ANDROID_BUILDING_ID, // geofenceId
				Constants.ANDROID_BUILDING_LATITUDE,
				Constants.ANDROID_BUILDING_LONGITUDE,
				Constants.ANDROID_BUILDING_RADIUS_METERS,
				Constants.GEOFENCE_EXPIRATION_TIME,
				Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit
			);
			mYerbaBuenaGeofence = new SimpleGeofence (
				Constants.YERBA_BUENA_ID, // geofenceId
				Constants.YERBA_BUENA_LATITUDE,
				Constants.YERBA_BUENA_LONGITUDE,
				Constants.YERBA_BUENA_RADIUS_METERS,
				Constants.GEOFENCE_EXPIRATION_TIME,
				Geofence.GeofenceTransitionEnter | Geofence.GeofenceTransitionExit
			);

			// Store these flat versions in SharedPreferences and add them to the geofence list
			mGeofenceStorage.SetGeofence (Constants.ANDROID_BUILDING_ID, mAndroidBuildingGeofence);
			mGeofenceStorage.SetGeofence (Constants.YERBA_BUENA_ID, mYerbaBuenaGeofence);
			mGeofenceList.Add (mAndroidBuildingGeofence.ToGeofence ());
			mGeofenceList.Add (mYerbaBuenaGeofence.ToGeofence ());
		}