this is the event in CrossGeofenceListener class.
public void OnRegionStateChanged(GeofenceResult result) { if (result.Transition == GeofenceTransition.Exited || result.Transition == GeofenceTransition.Entered) { MessagingCenter.Send(result, "region"); } }
In the constructor in my View class, I have added the subscriber like this..
MessagingCenter.Subscribe<GeofenceResult>(this, "region", async (region) => { await DisplayAlert("Region", region.TransitionName, "OK", "Cancel"); Region p = new Region() { Name = region.TransitionName.ToString() + "|" + region.RegionId, Latitude = region.Latitude, Longitude = region.Longitude, LastEnteredTime = (DateTime)region.LastEnterTime, LastExitedTime = (DateTime)region.LastExitTime }; model.LocationStatusCollection.Add(p); });
I have tested the messaging service using the messaging using a button.. The messaging center is working.
Can you tell me that why the OnRegionStateChanged not firing when changing the regions ?
this is the event in CrossGeofenceListener class.
public void OnRegionStateChanged(GeofenceResult result) { if (result.Transition == GeofenceTransition.Exited || result.Transition == GeofenceTransition.Entered) { MessagingCenter.Send(result, "region"); } }
In the constructor in my View class, I have added the subscriber like this..MessagingCenter.Subscribe<GeofenceResult>(this, "region", async (region) => { await DisplayAlert("Region", region.TransitionName, "OK", "Cancel"); Region p = new Region() { Name = region.TransitionName.ToString() + "|" + region.RegionId, Latitude = region.Latitude, Longitude = region.Longitude, LastEnteredTime = (DateTime)region.LastEnterTime, LastExitedTime = (DateTime)region.LastExitTime }; model.LocationStatusCollection.Add(p); });
I have tested the messaging service using the messaging using a button.. The messaging center is working.Can you tell me that why the OnRegionStateChanged not firing when changing the regions ?
private async void Button_Clicked(object sender, EventArgs e) { try { GeofenceResult result = new GeofenceResult() { Transition = GeofenceTransition.Exited, RegionId = "Depot", Latitude = 6.92034, Longitude = 79.857705, LastEnterTime = DateTime.Now.AddMinutes(-5), LastExitTime = DateTime.Now }; MessagingCenter.Send(result, "region"); } catch (Exception ex) { await DisplayAlert("",ex.Message,"OK"); } }