Ejemplo n.º 1
0
		public MapViewModel ()
		{
			Data = new ObservableCollection<Place> ();


			//Restored regions
			foreach (var region in CrossGeofence.Current.Regions.Values) 
			{
				var place = new Place () {
					Name = region.Id,
					Latitude = region.Latitude,
					Longitude = region.Longitude,
					Radius = region.Radius,
				};
				Data.Add (place);

			}
				
			IsBusy = true;
		}
Ejemplo n.º 2
0
		private async Task AddGeofence()
		{
			PromptResult result=await UserDialogs.Instance.PromptAsync ("Enter geofence region name", "Add Geofence");

			if (result.Ok) {
				
				try {
					PromptResult result1 = await UserDialogs.Instance.PromptAsync ("Enter radius (in meters)", "Geofence Radius", "Ok", "Cancel", "", InputType.Number);
					double radius = 50;
					if (!string.IsNullOrEmpty (result1.Text)) {
						radius = double.Parse (result1.Text);
					}


					UserDialogs.Instance.ShowLoading ();

					var place=new Place () {
						Name = result.Text,
						Latitude = Latitude,
						Longitude = Longitude,
						Radius = radius
					};


					Data.Add (place);
					CrossGeofence.Current.StartMonitoring(new GeofenceCircularRegion (place.Name,place.Latitude,place.Longitude,place.Radius) {

						NotifyOnStay=true,
						StayedInThresholdDuration=TimeSpan.FromMinutes(5)

					});


					MessagingCenter.Send<MapViewModel,Place>(this,"AddPin",place);

					UserDialogs.Instance.HideLoading ();

					await UserDialogs.Instance.AlertAsync(string.Format("{0} geofence region added!",place.Name));


				} catch (Exception ex) {
					Debug.WriteLine (ex.ToString ());
				}finally{
					IsEditing = false;
				}



			} else {
				IsEditing = false;
			}
		}
Ejemplo n.º 3
0
		void AddPin(Place a)
		{
			var position = new Xamarin.Forms.Maps.Position(a.Latitude,a.Longitude); 
			var pin = new Pin {
				Type = PinType.Place,
				Position = position,
				Label =a.Name,
				Address=string.Format("Radius: {0}",a.Radius)

			};
			mapView.Pins.Add(pin);
			Debug.WriteLine("TTTT");

		}