私はWindows 10 UWPアプリケーションを持っており、ジオフェンシングを統合しようとしています。私はGeofenceが円でなければならないという文書を読んだ。これはまだ本当ですか?矩形がサポートされないのはなぜですか?私の心の中のほとんどのジオフェンスが長方形になるので、それはばかげているようです。たとえば、私の家、庭、建物、公園などは、円よりも長方形(通常)です。これは、大部分のWindowsユニバーサルのサンプルから取られた後、私はそれを修正Windows 10 UWP Geofence Geofenceは円でなければなりませんか?
private Geofence GenerateGeofence()
{
string fenceKey = new string(Id.Text.ToCharArray());
BasicGeoposition positionNW;
positionNW.Latitude = double.Parse(LatitudeNW.Text);
positionNW.Longitude = double.Parse(LongitudeNW.Text);
positionNW.Altitude = 0.0;
BasicGeoposition positionSE;
positionSE.Latitude = double.Parse(LatitudeSE.Text);
positionSE.Longitude = double.Parse(LongitudeSE.Text);
positionSE.Altitude = 0.0;
// the geofence can be a circular region. However, we are going to use a rectangle
GeoboundingBox geoRect = new GeoboundingBox(positionNW, positionSE);
//Lock into false for single use because we don't want that feature for now.
bool singleUse = false;
// want to listen for enter geofence, exit geofence and remove geofence events
// you can select a subset of these event states
MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed;
TimeSpan dwellTime;
TimeSpan duration;
DateTimeOffset startTime;
var maxTimeSpan = TimeSpan.MaxValue;
try
{
//We are going to just hard set the dwell time to 5 seconds for now.
dwellTime = new TimeSpan(ParseTimeSpan("0", defaultDwellTimeSeconds));
// setting up how long you need to be in geofence for enter event to fire
//if (string.Empty != DwellTime.Text)
//{
// dwellTime = new TimeSpan(ParseTimeSpan(DwellTime.Text, defaultDwellTimeSeconds));
//}
//else
//{
// dwellTime = new TimeSpan(ParseTimeSpan("0", defaultDwellTimeSeconds));
//}
// setting up how long the geofence should be active
if (string.Empty != Duration.Text)
{
duration = new TimeSpan(ParseTimeSpan(Duration.Text, 0));
}
else
{
duration = maxTimeSpan;
}
// setting up the start time of the geofence
if (string.Empty != StartTime.Text)
{
startTime = DateTimeOffset.Parse(StartTime.Text);
}
else
{
// if you don't set start time in C# the start time defaults to 1/1/1601
calendar.SetToNow();
startTime = calendar.GetDateTime();
}
}
catch (ArgumentNullException)
{
}
catch (FormatException)
{
_rootPage.NotifyUser("Entered value is not a valid string representation of a date and time", NotifyType.ErrorMessage);
}
catch (ArgumentException)
{
_rootPage.NotifyUser("The offset is greater than 14 hours or less than -14 hours.", NotifyType.ErrorMessage);
}
return new Geofence(fenceKey, geoRect, mask, singleUse, dwellTime, startTime, duration);
}
:ここ
は、私が試したコードです。ご覧のように、APIには北東コーナーと南東のコーナーが必要なGeoboundingBoxがあります。それは四角形が考えられたようです。したがって、コードでわかるように、NW lat/longとSE lat/longを構築し、GeoboundingBoxオブジェクトを正常に作成することができます。私はこのラインで新しいジオフェンスを返した後は、しかし、私は例外を取得:
return new Geofence(fenceKey, geoRect, mask, singleUse, dwellTime, startTime, duration);
ジオフェンスオブジェクトコンストラクタは、ちょうどそれがで渡される形状を必要と言うが、それは明らかに境界が好きではありません。ボックス。コードを円に戻すと、次のようになります。
private Geofence GenerateGeofence()
{
string fenceKey = new string(Id.Text.ToCharArray());
BasicGeoposition positionNW;
positionNW.Latitude = double.Parse(LatitudeNW.Text);
positionNW.Longitude = double.Parse(LongitudeNW.Text);
positionNW.Altitude = 0.0;
BasicGeoposition positionSE;
positionSE.Latitude = double.Parse(LatitudeSE.Text);
positionSE.Longitude = double.Parse(LongitudeSE.Text);
positionSE.Altitude = 0.0;
// the geofence can be a circular region. However, we are going to use a rectangle
Geocircle geoCircle = new Geocircle(positionNW, 5.0);
//Lock into false for single use because we don't want that feature for now.
bool singleUse = false;
// want to listen for enter geofence, exit geofence and remove geofence events
// you can select a subset of these event states
MonitoredGeofenceStates mask = MonitoredGeofenceStates.Entered | MonitoredGeofenceStates.Exited | MonitoredGeofenceStates.Removed;
TimeSpan dwellTime;
TimeSpan duration;
DateTimeOffset startTime;
var maxTimeSpan = TimeSpan.MaxValue;
try
{
//We are going to just hard set the dwell time to 5 seconds for now.
dwellTime = new TimeSpan(ParseTimeSpan("0", defaultDwellTimeSeconds));
// setting up how long you need to be in geofence for enter event to fire
//if (string.Empty != DwellTime.Text)
//{
// dwellTime = new TimeSpan(ParseTimeSpan(DwellTime.Text, defaultDwellTimeSeconds));
//}
//else
//{
// dwellTime = new TimeSpan(ParseTimeSpan("0", defaultDwellTimeSeconds));
//}
// setting up how long the geofence should be active
if (string.Empty != Duration.Text)
{
duration = new TimeSpan(ParseTimeSpan(Duration.Text, 0));
}
else
{
duration = maxTimeSpan;
}
// setting up the start time of the geofence
if (string.Empty != StartTime.Text)
{
startTime = DateTimeOffset.Parse(StartTime.Text);
}
else
{
// if you don't set start time in C# the start time defaults to 1/1/1601
calendar.SetToNow();
startTime = calendar.GetDateTime();
}
}
catch (ArgumentNullException)
{
}
catch (FormatException)
{
_rootPage.NotifyUser("Entered value is not a valid string representation of a date and time", NotifyType.ErrorMessage);
}
catch (ArgumentException)
{
_rootPage.NotifyUser("The offset is greater than 14 hours or less than -14 hours.", NotifyType.ErrorMessage);
}
return new Geofence(fenceKey, geoCircle, mask, singleUse, dwellTime, startTime, duration);
}
うまくいきます。
だから、誰かが私がそれを長方形で動作させる方法を知っていますか?
ありがとうございます!
これは残念です。ありがとうございました!私は他の何かを描く必要があります。 –