我是初学者,我需要一些帮助,我正在为Windows Phone 8做我的应用程序,我有导航到项目的问题,就像指导,例如从购物到项目信息和地图中显示。我使用Web服务器将所有数据放在那里,并与我的应用程序连接。正在寻找我的实际位置,但是对于navigateitem是空的,它不能因为它(itempage)而转到另一个xaml。
public ItemPage()
{
InitializeComponent();
this.DataContext = Globals.NavigationItem;
MapOverlay overlay = new MapOverlay();
overlay.Content = new Pushpin() { Background = new SolidColorBrush(Colors.Green) }; ;
overlay.GeoCoordinate = Globals.MyPosition;
MapOverlay itemoverlay = new MapOverlay();
itemoverlay.Content = new Pushpin() { Background = new SolidColorBrush(Colors.Blue) };
itemoverlay.GeoCoordinate = new GeoCoordinate(double.Parse(Globals.NavigationItem.Latitude), double.Parse(Globals.NavigationItem.Longitude));
MapLayer layer = new MapLayer();
layer.Add(overlay);
Mymap.Layers.Add(layer);
MapLayer itemlayer = new MapLayer();
itemlayer.Add(itemoverlay);
Mymap.Layers.Add(itemlayer);
Mymap.Center = new GeoCoordinate(double.Parse(Globals.NavigationItem.Latitude), double.Parse(Globals.NavigationItem.Longitude));
Mymap.ZoomLevel = 15;
}
实际位置运作良好
private void GetUserLocation()
{
GeoCoordinateWatcher geo = new GeoCoordinateWatcher();
geo.PositionChanged += (x, y) =>
{
Globals.MyPosition = y.Position.Location;
};
geo.Start();
}
这是从购物xaml导航到项目xaml
private void Grid_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Globals.NavigationItem = (sender as Grid).DataContext as Item;
NavigationService.Navigate(new Uri("/Views/ItemPage.xaml", UriKind.RelativeOrAbsolute));
}
我很抱歉也许问题是愚蠢但很喜欢我在开始时说我完全是初学者,希望有人可以帮助我:)
=> 我想知道也许这里有一些错误,因为实际位置很好,服务器正在工作,因为拿了数据并把
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
ServiceReference1.Service1Client client = new ServiceReference1.Service1Client();
client.GetZakupyAsync();
client.GetZakupyCompleted += (x, y) =>
{
if (Globals.MyPosition != null)
{
ZakupyBox.ItemsSource = y.Result.Where(p => Globals.MyPosition.GetDistanceTo(new GeoCoordinate(double.Parse(p.Latitude), double.Parse(p.Longitude))) < 5000);
if (ZakupyBox.Items.Count == 0)
{
ZakupyBox.ItemsSource = y.Result;
}
}
else
{
ZakupyBox.ItemsSource = y.Result;
}
};
}