当前位置: 首页>>代码示例>>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;未经允许,请勿转载。