Code example for LocationClient

Methods: addGeofences, requestLocationUpdates

1
	} 
 
	@Override 
	public void onConnected(Bundle arg0) {
		Toast.makeText(this, "Connected", Toast.LENGTH_LONG).show();
		mClient.requestLocationUpdates(mRequest, this);
		 
		// Build a Geofence 
		Geofence fence = new Geofence.Builder()
				.setRequestId("1")
				.setCircularRegion(22.998881, 120.216082, 2000)
				.setTransitionTypes(Geofence.GEOFENCE_TRANSITION_ENTER)
				.setExpirationDuration(Geofence.NEVER_EXPIRE)
				.build();
		mList.add(fence);
		 
		/* 
		// Method 1: Using IntentService 
		// Create a Intent to be sent to IntentService 
		Intent intent = new Intent(this, GeofenceIntentSerivce.class); 
		intent.setAction("GeofenceIntentSerivce"); 
		// Start a PendingIntent service 
		PendingIntent pendingIntent = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); 
		*/ 
		 
		// Method 2: Using Broadcast 
		Intent intent = new Intent();
		intent.setAction(GeofenceEventReceiver.GEOFENCE_EVENTS); // Specify the action, a.k.a. receivers
		intent.addCategory(Intent.CATEGORY_DEFAULT);
		intent.putExtra("Location", "NCKU");
		PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
		// Send out the Geofence request 
		mClient.addGeofences(mList, pendingIntent, this);
	} 
 
	@Override 
	public void onDisconnected() {