private void AddAppBarButton_Click(object sender, RoutedEventArgs e)
        {
            Name_im pi = new Name_im {
                name_of_point = name_tob.Text.ToString(), image_of_point = text
            };

            this.Frame.Navigate(typeof(MapPage), pi);
        }
예제 #2
0
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.Parameter != null)
            {
                geolocator.DesiredAccuracyInMeters = 150;
                // получаем позицию
                var position = await geolocator.GetGeopositionAsync();

                // установка этой позиции на карте
                // Specify a known location.
                BasicGeoposition snPosition = new BasicGeoposition()
                {
                    Latitude = position.Coordinate.Point.Position.Latitude, Longitude = position.Coordinate.Point.Position.Longitude
                };
                Geopoint snPoint = new Geopoint(snPosition);

                // Create a MapIcon.
                MapIcon mapIcon2 = new MapIcon();
                mapIcon2.Location = snPoint;
                mapIcon2.NormalizedAnchorPoint = new Point(0.5, 1.0);
                Name_im top = (Name_im)e.Parameter;
                mapIcon2.Title = top.name_of_point.ToString();
                if (top.image_of_point == 0)
                {
                    mapIcon2.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/0.png"));
                }
                if (top.image_of_point == 1)
                {
                    mapIcon2.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/1.png"));
                }
                if (top.image_of_point == 2)
                {
                    mapIcon2.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/2.png"));
                }
                if (top.image_of_point == 3)
                {
                    mapIcon2.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/3.png"));
                }
                if (top.image_of_point == 4)
                {
                    mapIcon2.Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/4.png"));
                }
                mapIcon2.ZIndex = 0;
                objectList.Add(mapIcon2);
                // Add the MapIcon to the map.
                foreach (MapIcon o in objectList)
                {
                    map.MapElements.Add(o);
                }
                map.Center    = snPoint;
                map.ZoomLevel = 14;
            }

            else
            {
                try
                {
                    MessageDialog msd = new MessageDialog("Приложение пытается определить ваше местоположение", "Внимание");

                    msd.Commands.Add(new UICommand("Разрешить")
                    {
                        Id = 0
                    });
                    msd.Commands.Add(new UICommand("Запретить")
                    {
                        Id = 1
                    });
                    msd.DefaultCommandIndex = 0;
                    msd.CancelCommandIndex  = 1;

                    var result = await msd.ShowAsync();

                    if (result == null && result.Label == "Разрешить")
                    {
                        map.MapServiceToken = "mapToken";
                        // получаем инструмент геолокации

                        //точность геолокации до 150 метров
                        geolocator.DesiredAccuracyInMeters = 150;
                        // получаем позицию
                        var position = await geolocator.GetGeopositionAsync();

                        // установка этой позиции на карте
                        // Specify a known location.
                        BasicGeoposition snPosition = new BasicGeoposition()
                        {
                            Latitude = position.Coordinate.Point.Position.Latitude, Longitude = position.Coordinate.Point.Position.Longitude
                        };
                        Geopoint snPoint = new Geopoint(snPosition);

                        // Create a MapIcon.
                        MapIcon mapIcon1 = new MapIcon();
                        mapIcon1.Location = snPoint;
                        mapIcon1.NormalizedAnchorPoint = new Point(0.5, 1.0);
                        mapIcon1.Title  = "Вы";
                        mapIcon1.ZIndex = 0;

                        // Add the MapIcon to the map.
                        map.MapElements.Add(mapIcon1);

                        // Center the map over the POI.
                        map.Center    = snPoint;
                        map.ZoomLevel = 14;
                    }
                }
                catch
                {
                    MessageDialog msgbox = new MessageDialog("Невозможно получить данные местоположения", "Ошибка");
                    await msgbox.ShowAsync();
                }
            }
        }