當前位置: 首頁>>代碼示例>>Java>>正文


Java Geofence.Builder方法代碼示例

本文整理匯總了Java中com.google.android.gms.location.Geofence.Builder方法的典型用法代碼示例。如果您正苦於以下問題:Java Geofence.Builder方法的具體用法?Java Geofence.Builder怎麽用?Java Geofence.Builder使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.google.android.gms.location.Geofence的用法示例。


在下文中一共展示了Geofence.Builder方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addFence

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
private void addFence(double latitude, double longitude, float radius,
        String requestId, String broadcastUri) {
    if (!servicesConnected()) {
        return;
    }

    Geofence.Builder builder = new Geofence.Builder();
    builder.setRequestId(requestId);
    builder.setCircularRegion(latitude, longitude, radius);
    builder.setExpirationDuration(Geofence.NEVER_EXPIRE); // 無期限
    builder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER);

    // フェンスのListを作成する。
    List<Geofence> fenceList = new ArrayList<Geofence>();
    fenceList.add(builder.build());

    // フェンス內に入った時に、指定のURIを表示するインテントを投げるようにする。
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(broadcastUri));
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    mLocationClient.addGeofences(fenceList, pendingIntent, this);
}
 
開發者ID:TechBooster,項目名稱:effective_android_sample,代碼行數:24,代碼來源:MainActivity.java

示例2: toGeofence

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
private Geofence toGeofence(AddressInfo addressInfo) {
    Geofence.Builder geofenceBuilder = new Geofence.Builder();
    geofenceBuilder.setRequestId(addressInfo.uri.toString());
    geofenceBuilder.setExpirationDuration(Geofence.NEVER_EXPIRE);
    geofenceBuilder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT |
            Geofence.GEOFENCE_TRANSITION_DWELL);
    geofenceBuilder.setNotificationResponsiveness(NOTIFICATION_RESPONSIVENESS_MS);
    geofenceBuilder.setCircularRegion(addressInfo.latitude, addressInfo.longitude, RADIUS_M);
    geofenceBuilder.setLoiteringDelay(DISMISS_TIMEOUT_MS);
    return geofenceBuilder.build();
}
 
開發者ID:BoD,項目名稱:DoorCodeNotifier,代碼行數:12,代碼來源:GeofencingService.java

示例3: startGeofence

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
private void startGeofence() {
	Location location = mLocationClient.getLastLocation();

	Geofence.Builder builder = new Geofence.Builder();
	mGeofence = builder.setRequestId( FENCE_ID )
			.setCircularRegion( location.getLatitude(), location.getLongitude(), RADIUS )
			.setTransitionTypes( Geofence.GEOFENCE_TRANSITION_ENTER | Geofence.GEOFENCE_TRANSITION_EXIT )
			.setExpirationDuration( Geofence.NEVER_EXPIRE )
			.build();

	ArrayList<Geofence> geofences = new ArrayList<Geofence>();
	geofences.add( mGeofence );
	mLocationClient.addGeofences( geofences, mPendingIntent, this );
}
 
開發者ID:Lakkichand,項目名稱:AndroidDemoProjects,代碼行數:15,代碼來源:MainActivity.java

示例4: getGeofence

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
/**
 * This should return the geofence that this client wants to register.
 *
 * @param requestId
 *         The request ID for the geofence. *If this request ID is not set, the geofence will
 *         not work!*
 *
 * @return This client's geofence.
 */
@Override
public Geofence getGeofence(String requestId)
{
    mRequestId = requestId;

    Geofence.Builder builder = new Geofence.Builder();
    builder.setCircularRegion(getLatitude(), getLongitude(), getRadius());
    builder.setExpirationDuration(Geofence.NEVER_EXPIRE);
    builder.setRequestId(requestId);
    builder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                               Geofence.GEOFENCE_TRANSITION_EXIT);
    return builder.build();
}
 
開發者ID:Forkk,項目名稱:AutoCron,代碼行數:23,代碼來源:LocationRule.java

示例5: toGeofence

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
/**
 * Method for creating a Location Services Geofence object from a
 * SimpleGeofence object.
 * 
 * @return A Geofence object
 */
public Geofence toGeofence() {
	Geofence.Builder builder = new Geofence.Builder();
	builder.setRequestId(getId());
	builder.setTransitionTypes(getTransitionType());
	builder.setCircularRegion(getLatitude(), getLongitude(), getRadius());
	builder.setExpirationDuration(getExpirationDuration());

	return builder.build();
}
 
開發者ID:simonjrp,項目名稱:ESCAPE,代碼行數:16,代碼來源:SimpleGeofence.java

示例6: downloadContent

import com.google.android.gms.location.Geofence; //導入方法依賴的package包/類
private String downloadContent(String myurl) throws IOException {
    InputStream is = null;

    try {
        URL url = new URL(myurl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setReadTimeout(30000);
        conn.setConnectTimeout(30000);
        conn.setRequestMethod("GET");
        conn.setDoInput(true);
        conn.connect();
        int response = conn.getResponseCode();
        Log.d(TAG, "HTTP Response: " + response);
        is = conn.getInputStream();
        String contentAsString = convertStreamToString(is);

        try {
            // Parse the entire JSON string
            JSONObject root = new JSONObject(contentAsString);
            JSONObject user = root.getJSONObject("user");
            JSONArray tasks = user.getJSONArray("tasks");

            for(int i=0;i<tasks.length();i++) {
                // parse the JSON object into fields and values
                JSONObject jsonTasks = tasks.getJSONObject(i);
                String name = jsonTasks.getString("name");
                allTasks.add(name);
                int position = allTasks.indexOf(name);
                mapper.put(position, jsonTasks);
            }

        } catch (Exception e) {
            Log.d("Didgeridoo","Exception",e);
        }

        // Populate our geofence array with all our tasks
        for (int allTaskIndex = 0; allTaskIndex < allTasks.size(); allTaskIndex++) {
            JSONObject mapperData;

            try {
                mapperData = new JSONObject(mapper.get(allTaskIndex).toString());

                String taskName = mapperData.getString("name");
                double taskLat = Double.parseDouble(mapperData.getString("lat"));
                double taskLng = Double.parseDouble(mapperData.getString("long"));
                float taskRadius = Float.parseFloat(mapperData.getString("radius"));

                Geofence.Builder newBuilder = new Geofence.Builder();
                newBuilder.setRequestId(taskName);
                newBuilder.setCircularRegion(taskLat, taskLng, taskRadius);
                newBuilder.setExpirationDuration(Geofence.NEVER_EXPIRE);
                newBuilder.setLoiteringDelay(10000);
                newBuilder.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER |
                        Geofence.GEOFENCE_TRANSITION_EXIT |
                        Geofence.GEOFENCE_TRANSITION_DWELL);

                mGeofenceList.add(newBuilder.build());

            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }

        return contentAsString;
    } finally {
        if (is != null) {
            is.close();
        }
    }
}
 
開發者ID:Didgeridone,項目名稱:Didgeridone-Android,代碼行數:71,代碼來源:MainActivity.java


注:本文中的com.google.android.gms.location.Geofence.Builder方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。