windows-phone-8.1 geofencing

windows phone 8.1 - Cómo agregar Geofencing en el teléfono de windows silverlight 8.1



windows-phone-8.1 (0)

Quiero implementar Geofencing en mi proyecto Windows Phone 8, sé que la nueva API Geofencing se lanzó para Windows Phone 8.1, así que actualizo mi proyecto a Windows phone 8.1. Ahora mi proyecto se convierte en Windows Phone Silverlight 8.1. Quiero desencadenar Notificación en segundo plano así como también en primer plano cuando el usuario llegue a su ubicación deseada. He buscado mucho en google, pero todo lo que encontré para el teléfono 8.1 de Windows no es Silverlight 8.1. Traté de agregar esos ejemplos a mi aplicación para que no muestre ningún error, mi aplicación funciona bien pero no desencadena la geocerca ... Por favor, ¿alguien me puede ayudar con esto?

Aquí lo que he probado en mi aplicación es que tú también puedes ayudar con esto.

Primero hice una clase A con el siguiente código ...

public class GeofenceService { public static IList<Geofence> GetGeofence() { return GeofenceMonitor.Current.Geofences; } public static void CreateGeofence(string id, double lat, double lon, double radius) { if (GeofenceMonitor.Current.Geofences.FirstOrDefault(i => i.Id == id) != null) return; var position = new BasicGeoposition(); position.Latitude = lat; position.Longitude = lon; var geocircle = new Geocircle(position, radius); MonitoredGeofenceStates mask = 0; mask |= MonitoredGeofenceStates.Entered; var geofence = new Geofence(id, geocircle, mask, false, new TimeSpan(0, 0, 5)); GeofenceMonitor.Current.Geofences.Add(geofence); } public static void RemoveGeofence(string id) { var geofence = GeofenceMonitor.Current.Geofences.SingleOrDefault(g => g.Id == id); if (geofence != null) GeofenceMonitor.Current.Geofences.Remove(geofence); } }

Luego clase de tarea de fondo

public sealed class LocationTask : IBackgroundTask { static string TaskName = "GeofenceUniversalAppLocationTask"; public void Run(IBackgroundTaskInstance taskInstance) { // Uncomment this to utilize async/await in the task //var deferral = taskInstance.GetDeferral(); // Get the information of the geofence(s) that have been hit var reports = GeofenceMonitor.Current.ReadReports(); var report = reports.FirstOrDefault(r => (r.Geofence.Id == "MicrosoftStudioE") && (r.NewState == GeofenceState.Entered)); if (report == null) return; // Create a toast notification to show a geofence has been hit var toastXmlContent = ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02); var txtNodes = toastXmlContent.GetElementsByTagName("text"); txtNodes[0].AppendChild(toastXmlContent.CreateTextNode("Geofence triggered toast!")); txtNodes[1].AppendChild(toastXmlContent.CreateTextNode(report.Geofence.Id)); var toast = new ToastNotification(toastXmlContent); var toastNotifier = ToastNotificationManager.CreateToastNotifier(); toastNotifier.Show(toast); // Uncomment this to utilize async/await in the task //deferral.Complete(); } public async static void Register() { if (!IsTaskRegistered()) { var result = await BackgroundExecutionManager.RequestAccessAsync(); var builder = new BackgroundTaskBuilder(); builder.Name = TaskName; builder.TaskEntryPoint = typeof(LocationTask).FullName; builder.SetTrigger(new LocationTrigger(LocationTriggerType.Geofence)); // Uncomment this if your task requires an internet connection //var condition = new SystemCondition(SystemConditionType.InternetAvailable); //builder.AddCondition(condition); builder.Register(); } } public static void Unregister() { var entry = BackgroundTaskRegistration.AllTasks.FirstOrDefault(kvp => kvp.Value.Name == TaskName); if (entry.Value != null) entry.Value.Unregister(true); } public static bool IsTaskRegistered() { var taskRegistered = false; var entry = BackgroundTaskRegistration.AllTasks.FirstOrDefault(kvp => kvp.Value.Name == TaskName); if (entry.Value != null) taskRegistered = true; return taskRegistered; } }

y finalmente estoy llamando a la función Geofence para agregar Geolocalización y registrar tareas en segundo plano y también declaro correctamente en Packege.appxmanifest. pero aún no funciona :( por favor, tu ayuda será apreciada.