当位置改变时,我需要将用户位置更新到服务器。请告诉我如何实现这一点?
使用以下方法:
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");
}
}
请告诉我,每当用户更改其位置时,上述内容会更新位置吗?