2013-02-09 76 views
0

我正在制作一个简单的应用程序,使用http获取请求将位置数据发送到服务器。 问题是请求仅在第一次进行,尽管它位于positionchanged事件处理程序中。通过获取发送位置

这是我的代码。我找不到它有什么问题。

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Net; 
using System.Windows; 
using System.Windows.Controls; 
using System.Windows.Documents; 
using System.Windows.Input; 
using System.Windows.Media; 
using System.Windows.Media.Animation; 
using System.Windows.Shapes; 
using Microsoft.Phone.Controls; 
using System.Device.Location; 

namespace kechap 
{ 
    public partial class MainPage : PhoneApplicationPage 
    { 
     GeoCoordinateWatcher gw = new GeoCoordinateWatcher(); 

     Uri url = new Uri("http://127.0.0.1:5000/upload/1e3fae069dd62fa1641183cd77092ed2053a0e75/1/2"); 


     // Constructor 
     public MainPage() 
     { 
      InitializeComponent(); 
      gw.MovementThreshold = 10; 
      gw.PositionChanged += (s, e) => 
      { 
       MyMap.Center = e.Position.Location; 
       MyPushpin.Location = e.Position.Location; 

       WebClient wc = new WebClient(); 

       wc.OpenReadAsync(url); 
       wc.OpenReadCompleted += (ss, ee) => 
       { 
       };   
      }; 

      gw.Start(); 
     } 

    } 
} 

回答

2

在一个猜测中,我会说在你发布的代码中的URI不会在调用之间改变,在第一次之后从缓存中解析出来。我建议你使用旧的黑客追加一个参数,并给它一个随着每次调用而改变的值(例如,你似乎想要报告的位置)。

+0

这是我没有预料到的。我有固定的网址来测试它是否有效,这让我失望了。 – kechapito 2013-02-09 13:59:46

+0

在网络应用缓存的早期,我的存在是个祸根。有很多方法可以禁止它,包括将URL(正如我已经提到的)添加到各种HTML元标记和指令中。篡改URL是丑陋但可靠的。不利的一面是它膨胀了浏览器缓存。 – 2013-02-21 04:04:58