Beispiel #1
0
        async private void MyMap_OnLoaded(object sender, RoutedEventArgs e)
        {
            Geolocator locator = new Geolocator();

            locator.ReportInterval    = 2000;
            locator.MovementThreshold = 1;
            locator.PositionChanged  += (sender2, args) => {
                Geoposition pos = args.Position;
                string      la  = pos.Coordinate.Point.Position.Latitude.ToString();
                string      lo  = pos.Coordinate.Point.Position.Longitude.ToString();
                string      ac  = pos.Coordinate.Accuracy.ToString();
                apiSetLocation(la, lo, ac);
            };

            myMap        = (MapControl)sender;
            myMap.Center = new Geopoint(new BasicGeoposition()
            {
                Altitude = 643, Latitude = 43.089863, Longitude = -77.669609
            });
            myMap.ZoomLevel = 14;

            IEnumerable <Location> locations = await SampleDataSource.GetLocationsAsync();

            foreach (Location location in locations)
            {
                Double   la = Convert.ToDouble(location.Latitude);
                Double   lo = Convert.ToDouble(location.Longitude);
                Double   al = 643;
                Geopoint pt = new Geopoint(new BasicGeoposition()
                {
                    Latitude = la, Longitude = lo, Altitude = al
                });
                Windows.UI.Xaml.Shapes.Rectangle fence2 = new Windows.UI.Xaml.Shapes.Rectangle();
                fence2.Name    = location.Email;
                fence2.Tapped += fence_Tapped;
                fence2.Width   = 30;
                fence2.Height  = 30;
                BitmapImage img2 = new BitmapImage(new Uri("ms-appx:///Assets/redpin.png"));
                fence2.Fill = new ImageBrush()
                {
                    ImageSource = img2
                };
                myMap.Children.Add(fence2);
                MapControl.SetLocation(fence2, pt);
                MapControl.SetNormalizedAnchorPoint(fence2, new Point(1.0, 0.5));
            }
        }