0

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;
                }
            };            
    }
  • http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it –  May 13 '15 at 17:38
  • When do you call `GetUserLocation`? I don't see that in your code, and it might be the case that your `ItemPage` constructor completes initialization before the `PositionChanged` event has been raised / handled. – Peter Torr - MSFT May 14 '15 at 03:13
  • I tried to change it but maybe someone have a idea how to change it and it will be working – Karolina Bagrowska May 16 '15 at 12:04

0 Answers0