【发布时间】:2016-03-30 11:49:41
【问题描述】:
我是 Windows 10 的新手,目前正在开发基于位置的应用程序。我的要求是在特定时间间隔内跟踪用户位置,并每 10 分钟向服务器发送一次数据。有人可以建议这在 Windows 10 中是否可行?我不知道这一点。
更新
我也想在应用程序在后台时执行上述操作。我尝试了以下代码
protected override async void OnNavigatedTo(NavigationEventArgs e)
{
if (e.NavigationMode == NavigationMode.New)
{
var extendedSession = new ExtendedExecutionSession();
extendedSession.Reason = ExtendedExecutionReason.LocationTracking;
extendedSession.Description = "Location tracking";
ExtendedExecutionResult result = await extendedSession.RequestExtensionAsync();
if (result == ExtendedExecutionResult.Allowed)
{
Debug.WriteLine("Background execution approved");
}
else
{
Debug.WriteLine("Background execution denied");
}
Geolocator locator = new Geolocator();
locator.DesiredAccuracyInMeters = 0;
locator.MovementThreshold = 500;
locator.DesiredAccuracy = PositionAccuracy.High;
locator.PositionChanged += Locator_PositionChanged;
}
}
private void Locator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
Debug.WriteLine(args.Position.Coordinate.Latitude.ToString("0.00000000") + " " + args.Position.Coordinate.Longitude.ToString("0.00000000"));
if (MCSManager.Instance.userDetails != null && MCSManager.Instance.userDetails.LOC_TRACK_ENABLED.Equals("1") && userSettings.Values.ContainsKey(Constants.USER_ID))
{
DatabaseManager dbManager = new DatabaseManager();
Location_Tracking location_tracking = WebserviceED.StoreLocationData(args.Position.Coordinate.Latitude.ToString(),
args.Position.Coordinate.Longitude.ToString(), WebserviceED.getTimestamp(), args.Position.Coordinate.Accuracy.ToString());
var insertSuccessfull = dbManager.insertSingleRecord(location_tracking);
}
}
在这些中,我仅在应用程序处于前台或最小化时才能获取位置详细信息。如果我杀死该应用程序,它不会给我位置详细信息。另外,请帮助我如何在后台任务中使用它以及如何触发时间触发器以将数据发送到服务器,即使用户杀死了应用程序?
另外,我们可以使用多个后台任务吗?我想使用一个用于 TimeTrigger 将数据发送到服务器,另一个用于推送通知。
【问题讨论】:
-
有类似情况,见Real time GPS UWP。
-
您好,请在此页面上听取其他人的建议。您将需要了解地理定位和后台任务的基础知识。恐怕要大量阅读和学习。
-
编辑:在此页面上听取 Harshad Vekariya 的建议。您将需要了解地理定位和后台任务的基础知识。很多阅读和学习,我害怕。您在Sharpgis 下面的代码示例对您没有帮助。您需要做的是在 UWP 中 100% 可能,并且请注意,您只能在连接可用时将数据发送到服务器。祝你好运!
标签: c# win-universal-app windows-10