Code example for LocationManager

Methods: addProximityAlert

0
		Intent intent = new Intent(context, ReminderBroadCastReceiver.class); // Creating new intent to active with the reminder
		intent.putExtra("taskId", event.getId()); // Adding to the indent the task id to remind
		PendingIntent pi = PendingIntent.getBroadcast(context, (int)event.getId()+500, intent, 0); // Wrapping the intent in pending intent and adding it to the alarm manager with the task id+500(not to overwrite the reminder), so multiply reminders is available 
 
		LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // Getting the location manager		
		lm.addProximityAlert(latitude, longitude, 300, -1, pi);
 
	} 
 
	public void cancelProximityAlarm(Context context, long id)
	{ 
		LocationManager lm = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); // Getting the location manager
 
		PendingIntent pi = PendingIntent.getBroadcast(context, (int)id+500, new Intent(context, ReminderBroadCastReceiver.class), 0);
		lm.removeProximityAlert(pi);
 
	} 
}