0

지오 펜스를 사용하여 위치 기반 알림 응용 프로그램을 개발하려고합니다. 나는 단지 ana locaiton을 사용할 때 완벽하게 작동합니다. 그러나 두 위치를 추가하면 첫 번째 추가 된 위치에서만 작동합니다. 오류 또는 예외가 나타나지 않습니다. 그러나 두 번째 위치는 전혀 나타나지 않습니다. 나는 이것에 대한 이유를 찾을 수 없었다.WP 앱용 지오 펜스를 여러 개 추가하는 방법은 무엇입니까?

BasicGeoposition pos1 = new BasicGeoposition { Latitude = 6.931522, Longitude = 79.842005 }; 
    BasicGeoposition pos2 = new BasicGeoposition { Latitude = 6.978166, Longitude = 79.927376 }; 

     Geofence fence1 = new Geofence("loc", new Geocircle(pos1, 100)); 
     Geofence fence2 = new Geofence("loc", new Geocircle(pos2, 100)); 

     try 
     { 
      monitor.Geofences.Add(fence1); 
      monitor.Geofences.Add(fence2); 
     } 

이렇게 위치를 생성하고 지오 펜스에 추가하는 방법입니다. 그런 다음 루프와 함께 호출됩니다.

var reports = sender.ReadReports(); 
     await Dispatcher.RunAsync(CoreDispatcherPriority.High,() => 
     { 
      foreach (GeofenceStateChangeReport changeReport in reports) 
      { 
       if (changeReport.NewState == GeofenceState.Entered) 
       { 
        Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => 
         { 
          MessageDialog dialog = new MessageDialog("u re in the location"); 
          await dialog.ShowAsync(); 
         }); 
       } 
       if (changeReport.NewState == GeofenceState.Exited) 
       { 
        Dispatcher.RunAsync(CoreDispatcherPriority.High, async() => 
         { 
          MessageDialog dialog = new MessageDialog("u exited from the location"); 
          await dialog.ShowAsync(); 
         }); 

       } 
      } 
     }); 

답변

1

두 개의 울타리를 추가하지 않았습니다. 사실 당신은 단지 기존 덮어하려고 :

Geofence fence1 = new Geofence("loc", new Geocircle(pos1, 100)); 
Geofence fence2 = new Geofence("loc", new Geocircle(pos2, 100)); 

loc되어 그들은 당신이 당신의 울타리에 대한 열쇠 - (http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.geolocation.geofencing.geofence.aspx#constructors을)이 키가 고유해야합니다. 시도 :

Geofence fence1 = new Geofence("loc1", new Geocircle(pos1, 100)); 
Geofence fence2 = new Geofence("loc2", new Geocircle(pos2, 100)); 
난 당신이 또한 기존의 울타리를 확인해야하기 때문에 방법에 새로운 울타리를 추가 캡슐화 할 수 좋을 것

:

private void addGeoFence(Geopoint gp, String name, double radius) 
{ 
    // Always remove the old fence if there is any 
    var oldFence = GeofenceMonitor.Current.Geofences.Where(gf => gf.Id == name).FirstOrDefault(); 
    if (oldFence != null) 
     GeofenceMonitor.Current.Geofences.Remove(oldFence); 
    Geocircle gc = new Geocircle(gp.Position, radius); 
    // Listen for all events: 
    MonitoredGeofenceStates mask = 0; 
    mask |= MonitoredGeofenceStates.Entered; 
    mask |= MonitoredGeofenceStates.Exited; 
    mask |= MonitoredGeofenceStates.Removed; 
    // Construct and add the fence with a dwelltime of 5 seconds. 
    Geofence newFence = new Geofence(new string(name.ToCharArray()), gc, mask, false, TimeSpan.FromSeconds(5), DateTimeOffset.Now, new TimeSpan(0)); 
    GeofenceMonitor.Current.Geofences.Add(newFence); 
} 
+1

그것은 단지 전체 생성자의'지오 펜스 (문자열, IGeoshape , MonitoredGeofenceStates, Boolean, TimeSpan, DateTime, TimeSpan)'마지막 항목은 단일 사용, 휴지 시간, 시작 시간, 지오 펜스 지속 시간입니다. 자세한 내용은 답변과 함께 게시 한 링크를 참조하십시오. 가능한 모든 생성자를 볼 수 있습니다. – Fred

+0

나는 이것을 제외하고 모든 것을 시도했다. 당신의 도움을 주셔서 대단히 감사합니다. 나는 너의 suggetion에 대해 생각했다. 하지만 지오 펜스를 만들 때 전달하는 마지막 매개 변수에 대해 물어볼 수 있습니까 ?? 통과해야하는 항목 계속 확인하려면? 다시 많이 감사 드리며 정말로 도움을 주셔서 감사합니다. – user9480