I am totally beginner and I need some help, I am doing my application for Windows Phone 8 and I have problem with navigate to item, is like guide for example from shopping to show in item information and maps. I use web server to put all my data there and is connected with my application. Is looking for my actual position but is null with navigateitem and it can't go to another xaml because of it (itempage).
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;
}
The actual position is working well
private void GetUserLocation()
{
GeoCoordinateWatcher geo = new GeoCoordinateWatcher();
geo.PositionChanged += (x, y) =>
{
Globals.MyPosition = y.Position.Location;
};
geo.Start();
}
And this is navigate from shopping xaml to item 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));
}
I am sorry maybe question is stupid but liked I said in the beginning I am totally beginner, hope somebody can help me :)
=> I was wondering maybe here is some mistake because the actual location is good, server is working because took the data and put
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;
}
};
}