-1

当位置改变时,我需要将用户位置更新到服务器。请告诉我如何实现这一点?

使用以下方法:

void GeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            _pushpins.Clear();
            var cor = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            //Using the current coordinates define the Map center to those coordinates.
            map.Center = cor;

            _pushpins.Add(new PushpinModel
            {
                UserId=userId,
                Description = "test",
                Name = "test",
                Location = new GeoCoordinate(e.Position.Location.Latitude,
                                                e.Position.Location.Longitude),
                DatetimeAdded = DateTime.Now
            });

            map.ZoomLevel = 15;

            //locationupdate method
            locationupdate(e.Position.Location.Latitude,
                                                e.Position.Location.Longitude);

        }

    private void locationupdate(double lat,double lon)
        {
              bool isAvailable = NetworkInterface.GetIsNetworkAvailable();
                 if (isAvailable == true)
                 {
                     try
                     {

                         WebClient wc = new WebClient();
                         wc.DownloadStringAsync(
                         new Uri("http://{ipaddress}/Network/Records/UpdateLocation?userid="+userId+"&latitude="+lat+"&longitude="+lon));
                         wc.DownloadStringCompleted +=
                          new DownloadStringCompletedEventHandler(
                                         wc_DownloadStringUpdateCompleted);
                     }
                     catch (Exception ex)
                     {
                         throw;
                     }
                 }
                 else
                 {
                     MessageBox.Show("Network is not available.Please try again later");
                 }
       }

请告诉我,每当用户更改其位置时,上述内容会更新位置吗?

4

1 回答 1

0

分开你的目标...

您是否已经知道如何获取用户位置?

使用后台代理在后台运行任务(如有必要)http://www.silverlightshow.net/items/Windows-Phone-7.5-Use-Background-agents.aspx

创建一个网络服务来更新你的服务器

于 2012-06-21T06:47:36.500 回答