本文整理匯總了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);
}
示例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();
}
示例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 );
}
示例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();
}
示例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();
}
示例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();
}
}
}