2017-03-08 25 views
1

我需要在我的應用程序中進入和退出通知。所以我寫下了相同的代碼,並且按預期工作。但我想檢查多個覆蓋或區域。針對xamarin ios的多個區域的地理柵欄

對於一個例子,我已經設置了3個覆蓋圖或具有特定座標的區域。我想查看用戶當前位置附近區域的入口和出口。

  if (pointregion.ContainsCoordinate(location.Coordinate) && Entryregion == false) 
      { 
       Entryregion = true; Exitregion = false; 
       ShowNotification("You are just in " + pointregionname + " region", "Alert"); 
      } 
      if (!pointregion.ContainsCoordinate(location.Coordinate) && Entryregion == true) 
      { 
       Entryregion = false; Exitregion = true; 
       ShowNotification("You are just left " + pointregionname + " region", "Alert"); 
      } 

回答

0

您也許應該使用CLLocation​Manager的地區監測並設置地理圍欄區域。

  1. 創建CLCircularRegion或其他CLRegion類型的列表。

  2. 通過爲每個區域調用locationManager.StartMonitoring(yourRegion)來添加所有區域。

  3. 當你與一個特定區域進行調用locationManager.StopMonitoring(yourRegion)

然後當進入或離開RegionLeft(CLLocationManager manager, CLRegion region)RegionEntered(CLLocationManager manager, CLRegion region)委託方法將被稱爲區域中刪除。您需要在CLLocationManagerDelegate類中覆蓋這些方法。