Windows Phone 8.1 位置跟踪 [英] Windows Phone 8.1 location-tracking

查看:21
本文介绍了Windows Phone 8.1 位置跟踪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想实现一个连续发送设备位置到网络服务的应用程序.查看文档,我发现了 Geolocation 类和一些讨论位置跟踪的文章:

I want to realize an App that continuously send device's position to a web service. Looking in the documentation, I've found Geolocation class and some articles where position-tracking is discussed:

在实现这些文章中讨论的两个示例项目时,我注意到 geolocator_PositionChanged() 事件不会在每次位置更新时触发.两次执行事件之间存在延迟(大约 10/15 分钟).奇怪的是,即使应用程序在前台(不仅在后台)执行,也会发生这种情况.我使用的是 Windows Phone 模拟器.

Implementing both example projects discussed in these articles, I've noticed that the geolocator_PositionChanged() event is not fired at every position update. There is a delay (about 10/15 minutes) between 2 execution of the event. The strange thing is that this happens even when the App executes in foreground (not only in background). I'm using Windows Phone emulator.

在我的应用程序中,我有一个地图控件,我需要在其中显示用户的位置,因此,我需要为每个位置更新正确触发 geolocator_PositionChanged() 事件,没有延迟.

In my App I have a map control where I need to show user's position and, so, I need that the geolocator_PositionChanged() event be correctly fired for each position update, without delays.

1) 如何使用 Geolocator 类跟踪(无延迟)设备的位置?

1) How can I track (without delays) the device's position using Geolocator class?

通过网络搜索,我找到了 GeoCoordinateWatcher 类,它提供设备的连续位置跟踪.这是代码:

Searching over the network, I've found the GeoCoordinateWatcher class, that provides continuosly position-tracking of the device. This is the code:

public MainPage()
{
    InitializeComponent();
    this.GetCoordinate();
}

private void GetCoordinate()
{
    var watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
    {
        MovementThreshold = 1
    };
    watcher.PositionChanged += this.watcher_PositionChanged;
    watcher.Start();
}

private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
{
    //Get position data
    var pos = e.Position.Location;
    //Update mypos object
    mypos.update(pos.Latitude, pos.Longitude);
    //Update data on the main interface
    MainMap.SetView(mypos.getCoordinate(), MainMap.ZoomLevel, MapAnimationKind.Parabolic);
}

它有效:watcher_PositionChanged() 事件被立即触发.

It works: watcher_PositionChanged() event is fired without delays.

2) 为什么 GeoCoordinateWatcher 没有延迟?GeoCoordinateWatcher 类和 Geolocator 类有什么区别?

2) Why the GeoCoordinateWatcher does not have delays? What is the difference between GeoCoordinateWatcher class and Geolocator class?

最后,即使设备未处于活动状态,应用程序也应将设备的位置发送到网络服务.所以,我需要一个后台任务.正如 Romasz 在 此处 提出的,我可以使用 Geolocator有一些限制的类.

Finally, the App should send device's position to the web service even when it is not active. So, I need a background task. As proposed here by Romasz, I can use Geolocator class with some limitations.

3) 我可以在后台使用 GeoCoordinateWhatcher 吗?如果是,如何?

3) Can I use GeoCoordinateWhatcher in background? If yes, how?

我的目标是实现一个没有延迟的位置跟踪应用程序,它甚至可以在后台运行.做这个的最好方式是什么?该应用程序应跟踪设备的位置并不断更新网络服务(即使在后台).我怎样才能做到这一点?最好的方法是什么?我了解 Windows Phone 应用程序生命周期,我可以接受后台执行的一些限制.什么是背景限制?

My goal is to realize a position-tracking App without delays, that even works in background. What is the best way to do this? The App should track the device's position and continuously update the web service (even when in background). How can I do this? What is the best approach? I know about the Windows Phone Apps lifecycle and I can accept some limitations for the background execution. What are the background limits?

推荐答案

遗憾的是,Windows Phone 8.1 不支持后台连续跟踪.如果您想要此功能,则必须改为开发 Windows Phone 8 应用程序.希望他们会在 8.2、9 或接下来的任何版本中修复此问题!

Unfortunately Windows Phone 8.1 doesn't support continuous tracking in the background. If you want this feature you'll have to develop a Windows Phone 8 app instead. Hopefully they'll fix this for 8.2, 9 or whatever's next!

这篇关于Windows Phone 8.1 位置跟踪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆