Exemplo n.º 1
0
        private async void findMe()
        {
            Windows.Devices.Geolocation.Geolocator  geolocator  = new Windows.Devices.Geolocation.Geolocator();
            Windows.Devices.Geolocation.Geoposition geoposition = await geolocator.GetGeopositionAsync();

            myMap.SetView(new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            }, 13);
            Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.SetView(new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.Children.Clear();
            myMap.ShapeLayers.Clear();
            Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            });
            myMap.Children.Add(pin);
            sourseLocation = new Bing.Maps.Location()
            {
                Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude
            };
        }
Exemplo n.º 2
0
        private async void Pin_Dragged(Bing.Maps.Location obj)
        {
            //var client = new HttpClient();
            //Uri uri = new Uri("http://dev.virtualearth.net/REST/v1/Locations/" + obj.Latitude + "," + obj.Longitude + "?o=&key=AgRNfxvPZHZijcTen8d_YdjOczkXbxKLoIegltoNSdqhGqHmq5PpeZxDvyFw4HM6");
            //var response = await client.GetAsync(uri);
            //var result = await response.Content.ReadAsStringAsync();
            //MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
            //DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(Response));
            //var list = serializer.ReadObject(ms);
            //Response jsonResponse = list as Response;
            //ms.Flush();
            //if (jsonResponse.ResourceSets[0].EstimatedTotal!=0)
            //AddressTbl.Text = jsonResponse.ResourceSets[0].Resources[0].Address.FormattedAddress;
            var client   = new HttpClient();
            Uri Uri      = new Uri("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.Latitude + "," + obj.Latitude + "&key=AIzaSyDeJZgbdA56eyfwk660AZY0HrljWgpRtVc");
            var response = await client.GetAsync(Uri);

            var result = await response.Content.ReadAsStringAsync();

            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RootObject));
            var        list         = serializer.ReadObject(ms);
            RootObject jsonResponse = list as RootObject;

            AddressTbl.Text = jsonResponse.results[0].formatted_address;
        }
        private async void myMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
        {
            try
            {
#if WINDOWS_APP
                var pointerPosition = e.GetCurrentPoint(((Map)sender));

                Bing.Maps.Location location = null;

                //Convert the point pixel to a Location coordinate
                if (((Map)sender).TryPixelToLocation(pointerPosition.Position, out location))
                {
                    Bing.Maps.MapLayer.SetPosition(pin, location);
                    var client   = new HttpClient();
                    Uri Uri      = new Uri("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + location.Latitude + "," + location.Longitude + "&key=AIzaSyDeJZgbdA56eyfwk660AZY0HrljWgpRtVc");
                    var response = await client.GetAsync(Uri);

                    var result = await response.Content.ReadAsStringAsync();

                    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RootObject));
                    var        list         = serializer.ReadObject(ms);
                    RootObject jsonResponse = list as RootObject;
                    AddressTB.Text = jsonResponse.results[0].formatted_address;
                }
#endif
            }
            catch (Exception ex) { }
        }
Exemplo n.º 4
0
        private void Map_PointerReleased(object sender, PointerRoutedEventArgs e)
        {
            //Pushpin released, remove dragging events
            if (_map != null)
            {
                _map.ViewChanged             -= Map_ViewChanged;
                _map.PointerReleasedOverride -= Map_PointerReleased;
                _map.PointerMovedOverride    -= Map_PointerMoved;
            }

            var pointerPosition = e.GetCurrentPoint(_map);

            Bing.Maps.Location location = null;

            //Convert the point pixel to a Location coordinate
            if (_map.TryPixelToLocation(pointerPosition.Position, out location))
            {
                MapLayer.SetPosition(this, location);
            }

            if (DragEnd != null)
            {
                DragEnd(location);
            }

            this.isDragging = false;
        }
Exemplo n.º 5
0
        protected override void OnPointerPressed(PointerRoutedEventArgs e)
        {
            if (Draggable)
            {
                if (_map != null)
                {
                    //Store the center of the map
                    _center = _map.Center;

                    //Attach events to the map to track touch and movement events
                    _map.ViewChanged             += Map_ViewChanged;
                    _map.PointerReleasedOverride += Map_PointerReleased;
                    _map.PointerMovedOverride    += Map_PointerMoved;
                }

                var pointerPosition = e.GetCurrentPoint(_map);

                Bing.Maps.Location location = null;

                //Convert the point pixel to a Location coordinate
                if (_map.TryPixelToLocation(pointerPosition.Position, out location))
                {
                    MapLayer.SetPosition(this, location);
                }

                if (DragStart != null)
                {
                    DragStart(location);
                }

                //Enable Dragging
                this.isDragging = true;
            }
        }
Exemplo n.º 6
0
        // Tapped on omniBox
        private void listBoxHandler(object sender, TappedRoutedEventArgs e)
        {
            int selectedIndex = listBox.SelectedIndex;

            listBox.Visibility     = Visibility.Collapsed;
            controlsBG.Visibility  = Visibility.Visible;
            controlsBG2.Visibility = Visibility.Collapsed;
            try
            {
                int    ko = 0; // couter
                int    start;  // first no-hashtag symbol in string
                string pos     = "";
                int    counter = -1;
                while (ko < datalines.Length)
                {
                    ko++;
                    // Print in sourse/aim lable adress
                    if (((start = datalines[ko - 1].IndexOf("<text>")) != -1))
                    {
                        counter++;
                        if (counter != selectedIndex)
                        {
                            continue;
                        }
                        int nameLeng = datalines[ko - 1].Length;
                        textBox.Text = "";
                        if (!isSourseTapped)
                        {
                            sourseLable.Text = datalines[ko - 1].Substring(start + 6, nameLeng - 6 - start - 7);
                        }
                        else
                        {
                            aimLable.Text = datalines[ko - 1].Substring(start + 6, nameLeng - 6 - start - 7);
                        }
                    }
                    // Start contextPerform()
                    if (((start = datalines[ko - 1].IndexOf("<pos>")) != -1) && (counter == selectedIndex))
                    {
                        int posLenght = datalines[ko - 1].Length;
                        pos = datalines[ko - 1].Substring(start + 5, posLenght - 5 - start - 6);

                        double l1 = Convert.ToDouble(pos.Substring(0, pos.IndexOf('.')) + "," + pos.Substring(pos.IndexOf('.') + 1, pos.IndexOf(' ') - pos.IndexOf('.') - 1));

                        double l2 = Convert.ToDouble(pos.Substring(pos.IndexOf(' ') + 1, pos.IndexOf('.', pos.IndexOf('.') + 1) - pos.IndexOf(' ') - 1)
                                                     + ',' +
                                                     pos.Substring(pos.IndexOf('.', pos.IndexOf('.') + 1) + 1, pos.Length - (pos.IndexOf('.', pos.IndexOf('.') + 1) + 1)));


                        myMap.SetView(location = new Bing.Maps.Location()
                        {
                            Latitude = l2, Longitude = l1
                        });
                        contextPerform();
                        break;
                    }
                }
            }
            catch { MessageDialog dialog = new MessageDialog("Возникла непредвиденная ошибка. Очистите карту и попробуйте построить маршрут снова. Если ошибка повторится, сообщите нам о ней через форму обратной связи.", "Ошибка #007001"); }
        }
Exemplo n.º 7
0
        public Bing.Maps.LocationRect GetLocationsRect(ObservableCollection <Pin> locations, Location locationMy = null)
        {
            var boundingRect = new Bing.Maps.LocationRect();

            if (locations.Count == 0)
            {
                if (locationMy != null)
                {
                    boundingRect.Center = locationMy;
                }
            }
            else
            {
                double minLatitude  = locations[0].Coordinates.Latitude;
                double minLongitude = locations[0].Coordinates.Longitude;
                double maxLatitude  = locations[0].Coordinates.Latitude;
                double maxLongitude = locations[0].Coordinates.Longitude;
                if (locationMy != null)
                {
                    minLatitude  = locationMy.Latitude;
                    minLongitude = locationMy.Longitude;
                    maxLatitude  = locationMy.Latitude;
                    maxLongitude = locationMy.Longitude;
                }

                foreach (Pin loc in locations)
                {
                    if (loc.Coordinates.Latitude < minLatitude)
                    {
                        minLatitude = loc.Coordinates.Latitude;
                    }
                    else if (loc.Coordinates.Latitude > maxLatitude)
                    {
                        maxLatitude = loc.Coordinates.Latitude;
                    }

                    if (loc.Coordinates.Longitude < minLongitude)
                    {
                        minLongitude = loc.Coordinates.Longitude;
                    }
                    else if (loc.Coordinates.Longitude > maxLongitude)
                    {
                        maxLongitude = loc.Coordinates.Longitude;
                    }
                }

                double width  = maxLongitude - minLongitude;
                double height = maxLatitude - minLatitude;
                var    center = new Bing.Maps.Location(0.5 * (maxLatitude + minLatitude), 0.5 * (maxLongitude + minLongitude));
                if (locationMy != null)
                {
                    center = locationMy;
                }
                boundingRect.Center = center;
                boundingRect.Width  = width + 0.005;
                boundingRect.Height = height + 0.005;
            }
            return(boundingRect);
        }
 void MyMap_Tapped(object sender, TappedRoutedEventArgs e)
 {
     var pos = e.GetPosition(MyMap);
     Bing.Maps.Location location = new Bing.Maps.Location();
     miniTockeShapeLayer = new MapShapeLayer();
     MyMap.TryPixelToLocation(pos, out location);
     GetAddressByLocation(location);
     locationCollection.Add(location);
 }
Exemplo n.º 9
0
 private async void findMe()
 {
     Windows.Devices.Geolocation.Geolocator geolocator = new Windows.Devices.Geolocation.Geolocator();
     Windows.Devices.Geolocation.Geoposition geoposition = await geolocator.GetGeopositionAsync();
     myMap.SetView(new Bing.Maps.Location() { Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude }, 13);
     Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location() { Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude });
     myMap.SetView(new Bing.Maps.Location() { Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude });
     myMap.Children.Clear();
     myMap.ShapeLayers.Clear();
     Bing.Maps.MapLayer.SetPosition(pin, new Bing.Maps.Location() { Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude });
     myMap.Children.Add(pin);
     sourseLocation = new Bing.Maps.Location() { Latitude = geoposition.Coordinate.Latitude, Longitude = geoposition.Coordinate.Longitude };
 }
Exemplo n.º 10
0
        public void ProcessResponse(Response locationsResponse, MapApplication.Places place)
        {
            int locNum = locationsResponse.ResourceSets[0].Resources.Length;

            for (int i = 0; i < locNum; i++)
            {
                Location location = (Location)locationsResponse.ResourceSets[0].Resources[i];
                if (location.Confidence == "High")
                {
                    Pushpin push = new Pushpin();
                    push.Text    = location.Address.FormattedAddress;
                    push.Height  = 100;
                    push.Width   = 100;
                    push.Tapped += pushpinTapped;

                    Uri         imgUri     = new Uri(base.BaseUri, "/Images/pushpin.png");
                    BitmapImage imgSourceR = new BitmapImage(imgUri);
                    ImageBrush  imgBrush   = new ImageBrush()
                    {
                        ImageSource = imgSourceR
                    };

                    push.DataContext = new Rectangle()
                    {
                        Fill   = imgBrush,
                        Height = 100,
                        Width  = 100
                    };

                    Bing.Maps.Location locat = new Bing.Maps.Location(location.Point.Coordinates[0], location.Point.Coordinates[1]);
                    MapLayer.SetPosition(push, locat);
                    if (place.category == 1)
                    {
                        push.Background = new SolidColorBrush(Windows.UI.Colors.Red);
                    }
                    if (place.category == 2)
                    {
                        push.Background = new SolidColorBrush(Windows.UI.Colors.Violet);
                    }
                    if (place.category == 3)
                    {
                        push.Background = new SolidColorBrush(Windows.UI.Colors.Black);
                    }

                    map.Children.Add(push);
                    map.Center = locat;
                }
            }
        }
Exemplo n.º 11
0
        void InitializeMapData()
        {
            _geolocator = new Geolocator();
            FMobject = new FillModel();
            DMobject = new DataModel();
            POMobject = new PoliceOfficeModel();
            routeLayer = new MapShapeLayer();
            myMap.ShapeLayers.Add(routeLayer);
            FMobject.FillingModel();
            LV_POList.ItemsSource = FMobject.GovernrateList[0].POfficeList;

            var loc = new Bing.Maps.Location(29.837452, 31.362296);
            myMap.Center = loc;
            myMap.ZoomLevel = 6;
        }
Exemplo n.º 12
0
        private async void Pin_Dragged(Bing.Maps.Location obj)
        {
            var client   = new HttpClient();
            Uri Uri      = new Uri("https://maps.googleapis.com/maps/api/geocode/json?latlng=" + obj.Latitude + "," + obj.Longitude + "&key=AIzaSyDeJZgbdA56eyfwk660AZY0HrljWgpRtVc");
            var response = await client.GetAsync(Uri);

            var result = await response.Content.ReadAsStringAsync();

            MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(result));
            DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(RootObject));
            var        list         = serializer.ReadObject(ms);
            RootObject jsonResponse = list as RootObject;

            AddressTB.Text = jsonResponse.results[0].formatted_address;
        }
Exemplo n.º 13
0
        void MyMap_PointerPressedOverride(object sender, PointerRoutedEventArgs e)
        {
            Bing.Maps.Location l = new Bing.Maps.Location();
            this.MapPlace.TryPixelToLocation(e.GetCurrentPoint(this.MapPlace).Position, out l);
            Bing.Maps.Pushpin pushpin = new Bing.Maps.Pushpin();
            pushpin.SetValue(Bing.Maps.MapLayer.PositionProperty, l);
            this.MapPlace.Children.Add(pushpin);

            var rmain = ServiceLocator.Current.GetInstance <MainViewModel>();

            ///rmain.MyCoordinate = new Geoposition();
            rmain.Latitude  = l.Latitude;
            rmain.Longitude = l.Longitude;

            rmain.UpdateDistances();
            rmain.GetNearestItems();
        }
Exemplo n.º 14
0
    public void RefreshMap(DispatchNoteSummary selectedItem)
    {
      var location = new Location(selectedItem.Latitude, selectedItem.Longitude);
      if (location.Latitude == 0 && location.Longitude == 0) return;

      SetRoute(location, new Location(52.516071, 13.37698));
      var image = new Image
        {
          Source = new BitmapImage(new Uri(_baseUri, "/images/truck_map.png")),
          Width = 40,
          Height = 40
        };

      MapLayer.SetPosition(image, location);
      _mapTrucks.SetView(location);
      _mapTrucks.Children.Add(image);
    }
        public BriefDetailsUserControlViewModel()
        {
            Location = new Bing.Maps.Location();

            geolocator.PositionChanged += geolocator_PositionChanged;

            this.MakeIMCommand = DelegateCommand <string> .FromAsyncHandler(async (emailId) =>
            {
                await Launcher.LaunchUriAsync(new Uri("skype:shoaibrafi?chat"));
            }, (emailId) => { return(!string.IsNullOrEmpty(emailId)); });

            this.MakeSkypeCallCommand = DelegateCommand <string> .FromAsyncHandler(async (number) =>
            {
                await Launcher.LaunchUriAsync(new Uri("audiocall-skype-com:" + number));
            }, (number) => { return(!string.IsNullOrEmpty(number)); });

            this.MailToCommand = DelegateCommand <string> .FromAsyncHandler(async (email) =>
            {
                await Launcher.LaunchUriAsync(new Uri("mailto:" + email));
            }, (email) => { return(!string.IsNullOrEmpty(email)); });

            this.LocateCommand = DelegateCommand <string> .FromAsyncHandler(async (address) =>
            {
                await Launcher.LaunchUriAsync(new Uri("bingmaps:?where=" + Regex.Replace(address, "\n", ",")));
            }, (address) =>
            {
                return(!string.IsNullOrEmpty(address));
            });


            GetDirectionsCommand = DelegateCommand <string> .FromAsyncHandler(async (address) =>
            {
                var stringBuilder = new StringBuilder("bingmaps:?rtp=pos.");
                stringBuilder.Append(Location.Latitude);
                stringBuilder.Append("_");
                stringBuilder.Append(Location.Longitude);
                stringBuilder.Append("~adr." + Regex.Replace(address, "\n", ","));
                await Launcher.LaunchUriAsync(new Uri(stringBuilder.ToString()));
            }, (address) =>
            {
                return(!string.IsNullOrEmpty(address));
            });
        }
Exemplo n.º 16
0
        public void RefreshMap(DispatchNoteSummary selectedItem)
        {
            var location = new Location(selectedItem.Latitude, selectedItem.Longitude);

            if (location.Latitude == 0 && location.Longitude == 0)
            {
                return;
            }

            SetRoute(location, new Location(52.516071, 13.37698));
            var image = new Image
            {
                Source = new BitmapImage(new Uri(_baseUri, "/images/truck_map.png")),
                Width  = 40,
                Height = 40
            };

            MapLayer.SetPosition(image, location);
            _mapTrucks.SetView(location);
            _mapTrucks.Children.Add(image);
        }
Exemplo n.º 17
0
        private void Map_PointerMoved(object sender, PointerRoutedEventArgs e)
        {
            //Check if the user is currently dragging the Pushpin
            if (this.isDragging)
            {
                //If so, move the Pushpin to where the pointer is.
                var pointerPosition = e.GetCurrentPoint(_map);

                Bing.Maps.Location location = null;

                //Convert the point pixel to a Location coordinate
                if (_map.TryPixelToLocation(pointerPosition.Position, out location))
                {
                    MapLayer.SetPosition(this, location);
                }

                if (Drag != null)
                {
                    Drag(location);
                }
            }
        }
        private async Task <Bing.Maps.Location> GeocodePlaceName(string place)
        {
            Bing.Maps.Location geocodedPlace = new Bing.Maps.Location();

            GeocodeRequest geocodeRequest = new GeocodeRequest();

            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = BING_MAPS_KEY;

            geocodeRequest.Query = place;
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(
                GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
            GeocodeResponse geocodeResponse = await geocodeService.GeocodeAsync(geocodeRequest);

            if (geocodeResponse.Results.Count > 0)
            {
                geocodedPlace.Latitude  = geocodeResponse.Results[0].Locations[0].Latitude;
                geocodedPlace.Longitude = geocodeResponse.Results[0].Locations[0].Longitude;
            }

            return(geocodedPlace);
        }
Exemplo n.º 19
0
 public async void GetCurrentLocation()
 {
     try
     {
         Pushpin pushpin = new Pushpin();
         Geolocator MyGeolocator = new Geolocator();
         MyGeolocator.DesiredAccuracy = PositionAccuracy.High;
         Geoposition MyGeoposition = await MyGeolocator.GetGeopositionAsync();
         Latitude = MyGeoposition.Coordinate.Latitude;
         Longitude = MyGeoposition.Coordinate.Longitude;
         var CurrentLocation = new Bing.Maps.Location(Latitude, Longitude);
         MyMap.Center = CurrentLocation;
         MyMap.ZoomLevel = 15;
         MyMap.Children.Add(pushpin);
         MapLayer.SetPosition(pushpin, CurrentLocation);
     }
     catch
     {
         MessageDialog error = new MessageDialog("please check your internet conenction!!");
         error.ShowAsync();
     }
 }
Exemplo n.º 20
0
        private async void GetMyLocation()
        {
            // Get my current  location on the map 
            Geolocator myGeolocator = new Geolocator();
            Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
            Bing.Maps.Location mylocation = new Bing.Maps.Location(myGeoposition.Coordinate.Latitude, myGeoposition.Coordinate.Longitude);
            // Make my current location the center of the Map.
            this.myMap.Center = mylocation;
            this.myMap.ZoomLevel = 15;
            //Create a small shape to mark the current location.
            Pushpin pushpin = new Pushpin();
            pushpin.Text = "M";
            MapLayer.SetPosition(pushpin, mylocation);
            myMap.Children.Add(pushpin);


        }
Exemplo n.º 21
0
 //Automatically changes UserPushPin when the user's location changes
 async void _geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
 {
     try
     {
         await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
         {
             if (currentLoc != null && UserIsInRadius(10, new Bing.Maps.Location(args.Position.Coordinate.Point.Position.Latitude, args.Position.Coordinate.Point.Position.Longitude), currentLoc))
             {
                 //System.Diagnostics.Debug.WriteLine("Latitude:  {0} \nLongitude: {1}", args.Position.Coordinate.Point.Position.Latitude, args.Position.Coordinate.Point.Position.Longitude);
                 if (args.Position.Coordinate.Point.Position.Latitude > 0 && args.Position.Coordinate.Point.Position.Longitude > 0)
                 {
                     MapLayer.SetPosition(userPin, currentLoc);
                     drawMovedLine(currentLoc, new Bing.Maps.Location(args.Position.Coordinate.Point.Position.Latitude, args.Position.Coordinate.Point.Position.Longitude));
                     //zoomToLocation2(currentLoc);
                     OnUserPositionChanged(this, currentLoc);
                     currentLoc = new Bing.Maps.Location(args.Position.Coordinate.Point.Position.Latitude, args.Position.Coordinate.Point.Position.Longitude);
                 }
             }
         });
     }
     catch (Exception x)
     {
         System.Diagnostics.Debug.WriteLine(x);
         showInternetPopup();
     }
 }
Exemplo n.º 22
0
 //Zooms to the Users Location and makes a User PushPin
 private async void zoomToLocation()
 {
     try
     {
         _geolocator = null;
         _geolocator = new Geolocator();
         Geoposition currentPos = await _geolocator.GetGeopositionAsync();
         currentLoc = new Bing.Maps.Location(currentPos.Coordinate.Latitude, currentPos.Coordinate.Longitude);
         userPin = new Pushpin();
         ResourceLoader rl = new ResourceLoader();
         userPin.Text = rl.GetString("UserPinText");
         userPin.Background = new SolidColorBrush(new Windows.UI.Color { A = 100, B = 0, G = 0, R = 100 });
         MapLayer.SetPosition(userPin, currentLoc);
         Map.Children.Add(userPin);
         Map.SetView(currentLoc, 15.0);
         //_geolocator.MovementThreshold = 10;
         //_geolocator.ReportInterval = 500;
         _geolocator.DesiredAccuracy = PositionAccuracy.Default;
         _geolocator.PositionChanged += _geolocator_PositionChanged;
         timer = new DispatcherTimer();
         timer.Tick += timer_Tick;
         timer.Interval = new TimeSpan(0, 0, 0, 0, 2000);
         timer.Start();
         if(Finished == false)
         {
             Finished = true;
             zoomFinished = true;
             mc.createRoute();
         }
     }
     catch(Exception d)
     {
         System.Diagnostics.Debug.WriteLine(d);
         showInternetPopup();
     }
 }
        private async void CreateBubbles()
        {
            StringBuilder sb = new StringBuilder();

            byte[][] colourSchemeArray;
            int      nClassesValue = 3;
            string   colourSchemeComboBoxSelection = colourSchemeComboBox.SelectedValue.ToString();

            if (!_datasetModel.IsColourQualitative)
            {
                ComboBoxItem nClassesComboBoxSelection = (ComboBoxItem)numDataClassesComboBox.SelectedValue;
                nClassesValue     = int.Parse(nClassesComboBoxSelection.Content.ToString());
                colourSchemeArray = _colourScheme.GetRGBColours(colourSchemeComboBoxSelection, nClassesValue);
            }
            else
            {
                nClassesValue     = _distinctCategories.Count();
                colourSchemeArray = _colourScheme.GetRGBColours(colourSchemeComboBoxSelection, nClassesValue);
            }

            for (int i = 0; i < _datasetModel.Dataset.Count; i++)
            {
                string[] row = _datasetModel.Dataset[i];

                BubblePushpin bubble = new BubblePushpin();
                bubble.OriginalBubbleSize = double.Parse(row[_symbolSizeIndex]);
                bubble.BubbleSize         = bubble.OriginalBubbleSize;
                bubble.ColourValue        = row[_symbolColourIndex];

                // use StringBuilder to create the tooltip details
                sb.AppendLine(row[_placeNameIndex]);
                sb.Append(_datasetModel.ColumnHeadings[_symbolSizeIndex]);
                sb.Append(": ");
                sb.AppendLine(row[_symbolSizeIndex]);
                sb.Append(_datasetModel.ColumnHeadings[_symbolColourIndex]);
                sb.Append(": ");
                sb.Append(row[_symbolColourIndex]);
                if (!String.IsNullOrEmpty(this.Description))
                {
                    sb.Append(": ");
                    sb.Append(row[_descriptionIndex]);
                }
                bubble.Details = sb.ToString();

                // plot symbols on map - if lat/lon not set then geocode the place name
                if (String.IsNullOrEmpty(this.Latitude) || String.IsNullOrEmpty(this.Longitude) ||
                    String.IsNullOrEmpty(row[_latitideIndex]) || String.IsNullOrEmpty(row[_longitudeIndex]))
                {
                    Bing.Maps.Location geocodedLocation = await GeocodePlaceName(row[_placeNameIndex]);

                    bubble.LatLon = geocodedLocation;
                }
                else
                {
                    double latitude  = 0.0;
                    double longitude = 0.0;

                    if (!double.TryParse(row[_latitideIndex], out latitude) ||
                        !double.TryParse(row[_longitudeIndex], out longitude))
                    {
                        await new MessageDialog("Cannot parse latitude/longitude for " + row[_placeNameIndex],
                                                "Error parsing dataset").ShowAsync();
                    }

                    bubble.LatLon = new Bing.Maps.Location(latitude, longitude);
                }

                // Apply colour
                if (_datasetModel.IsColourQualitative)
                {
                    int index = _distinctCategories.IndexOf(row[_symbolColourIndex]);
                    bubble.Colour = colourSchemeArray[index];
                }
                else
                {
                    double colourValue     = double.Parse(row[_symbolColourIndex]);
                    double linearTransform = (colourValue - _datasetModel.ColourMinMax[0]) /
                                             (_datasetModel.ColourMinMax[1] - _datasetModel.ColourMinMax[0]) * (nClassesValue - 1);
                    int colourIndex = (int)Math.Truncate(linearTransform);
                    bubble.Colour = colourSchemeArray[colourIndex];
                }

                _bubblePushpins.Add(bubble);
                sb.Clear();
            }

            Draw();
        }
        // Incoming event - Annotations Changed
        void annotationCollection_AnnotationsChanged(object sender, AnnotationCollectionChangedEventArgs e)
        {
            foreach (IMapAnnotation item in e.annotationsAdded)
            {
                // We need the IAnnotationMarker to get the position anchor information
                IAnnotationMarker newAnnotationMarker = markerSource.MarkerForAnnotation(item);

                // Now cast to a normal UIElement
                UIElement newElement = (UIElement)newAnnotationMarker;

                Bing.Maps.Location loc = new Bing.Maps.Location(item.Latitude, item.Longitude );
                MapLayer.SetPosition(newElement, loc);
                MapLayer.SetPositionAnchor(newElement, newAnnotationMarker.PositionAnchor);

                annotationElements.Add(item, newElement);
                annotationsLayer.Children.Add(newElement);

                newElement.Tapped += annotation_Tapped;
            }
            foreach (IMapAnnotation item in e.annotationsRemoved)
            {
                UIElement oldPin;
                if (annotationElements.TryGetValue(item, out oldPin))
                {
                    annotationsLayer.Children.Remove(oldPin);
                    annotationElements.Remove(item);
                }
            }
        }
Exemplo n.º 25
0
        private async void SetRoute(Location startLocation, Location endLocation)
        {
            ClearMap();
            //Create the Request URL for the routing service
            const string request =
                @"http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0={0},{1}&wp.1={2},{3}&rpo=Points&key={4}";

            var routeRequest =
                new Uri(string.Format(request, startLocation.Latitude, startLocation.Longitude, endLocation.Latitude,
                                      endLocation.Longitude, _mapTrucks.Credentials));

            //Make a request and get the response
            var r = await GetResponse(routeRequest);

            if (r != null &&
                r.ResourceSets != null &&
                r.ResourceSets.Length > 0 &&
                r.ResourceSets[0].Resources != null &&
                r.ResourceSets[0].Resources.Length > 0)
            {
                var route = r.ResourceSets[0].Resources[0] as Route;
                if (route == null)
                {
                    return;
                }

                //Get the route line data
                var routePath = route.RoutePath.Line.Coordinates;
                var locations = new LocationCollection();

                foreach (var t in routePath)
                {
                    if (t.Length >= 2)
                    {
                        locations.Add(new Location(t[0], t[1]));
                    }
                }

                //Create a MapPolyline of the route and add it to the map
                var routeLine = new MapPolyline
                {
                    Color     = Colors.Blue,
                    Locations = locations,
                    Width     = 5
                };

                _routeLayer.Shapes.Add(routeLine);

                //Add start and end pushpins
                var start = new Pushpin
                {
                    Text       = "S",
                    Background = new SolidColorBrush(Colors.Green)
                };

                _mapTrucks.Children.Add(start);
                MapLayer.SetPosition(start,
                                     new Location(route.RouteLegs[0].ActualStart.Coordinates[0],
                                                  route.RouteLegs[0].ActualStart.Coordinates[1]));

                var end = new Pushpin
                {
                    Text       = "E",
                    Background = new SolidColorBrush(Colors.Red)
                };

                _mapTrucks.Children.Add(end);
                MapLayer.SetPosition(end,
                                     new Location(route.RouteLegs[0].ActualEnd.Coordinates[0],
                                                  route.RouteLegs[0].ActualEnd.Coordinates[1]));

                //Set the map view for the locations
                var locationRect = new LocationRect(locations);
                locationRect.Width  += 0.5;
                locationRect.Height += 0.5;
                _mapTrucks.SetView(locationRect);
            }
        }
Exemplo n.º 26
0
        private async void searchPane_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)
        {
            //throw new NotImplementedException();
            myMap.Children.Clear();

            //Logic for geaocding the query text
            if (!string.IsNullOrWhiteSpace(args.QueryText))
            {
                await new  MessageDialog(args.QueryText).ShowAsync();
                Uri geocodeUri = new Uri(
                    string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&c={1}&key={2}",
                                  Uri.EscapeUriString(args.QueryText), args.Language, myMap.Credentials));

                //Get response from Bing Maps REST services
                Response r = await GetResponse(geocodeUri);

                if (r != null &&
                    r.ResourceSets != null &&
                    r.ResourceSets.Length > 0 &&
                    r.ResourceSets[0].Resources != null &&
                    r.ResourceSets[0].Resources.Length > 0)
                {
                    LocationCollection locations = new LocationCollection();

                    int i = 1;
                    foreach (BingMapsRESTService.Common.JSON.Location l
                             in r.ResourceSets[0].Resources)
                    {
                        //Get the Location of each result
                        Bing.Maps.Location location = new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);
                        //Create a pushpin each location
                        Pushpin pin = new Pushpin()
                        {
                            Tag  = l.Name,
                            Text = i.ToString()
                        };
                        i++;

                        //Add a tapped event that will displau the name of the location
                        pin.Tapped += async(s, a) =>
                        {
                            var p = s as Pushpin;
                            await new MessageDialog(p.Tag as string).ShowAsync();
                        };
                        //Set the location of the pushpin
                        MapLayer.SetPosition(pin, location);

                        //add th pushpin to the map
                        myMap.Children.Add(pin);

                        //Add the coordinates of the location to a location collection
                        locations.Add(location);
                    }//End foreach

                    //set the map view based on the location collection
                    myMap.SetView(new LocationRect(locations));
                }//End IF
                else
                {
                    await new MessageDialog("Nenhum resultado encontrado..").ShowAsync();
                }
            }
        }
Exemplo n.º 27
0
        public void UpdateUserRadius(String Radius,Bing.Maps.Location loc)
        {
            var R = 6371;

            var radius = Radius;      //radius of the circle
            var latitude = loc.Latitude;    //latitude of the circle center
            var longitude = loc.Longitude;   //longitude of the circle center

            var lat = (latitude * Math.PI) / 180;
            var lon = (longitude * Math.PI) / 180;
            var d = float.Parse(radius) / R;
            var circlePoints = new LocationCollection();

            for (int x = 0; x <= 360; x += 5)
            {
                var p2 = new Bing.Maps.Location(0, 0);
                var brng = x * Math.PI / 180;
                p2.Latitude = Math.Asin(Math.Sin(lat) * Math.Cos(d) + Math.Cos(lat) * Math.Sin(d) * Math.Cos(brng));

                p2.Longitude = ((lon + Math.Atan2(Math.Sin(brng) * Math.Sin(d) * Math.Cos(lat),
                                 Math.Cos(d) - Math.Sin(lat) * Math.Sin(p2.Latitude))) * 180) / Math.PI;
                p2.Latitude = (p2.Latitude * 180) / Math.PI;
                circlePoints.Add(p2);
            }

            userRadius = new LocationRect(circlePoints);
            var u = 0.001;
            userRadius = new LocationRect(new LocationCollection{ loc, new Bing.Maps.Location(loc.Latitude+u,loc.Longitude),new Bing.Maps.Location(loc.Latitude,loc.Longitude+u),
            new Bing.Maps.Location(loc.Latitude+u,loc.Longitude+u), new Bing.Maps.Location(loc.Latitude-u,loc.Longitude), new Bing.Maps.Location(loc.Latitude,loc.Longitude-u),
            new Bing.Maps.Location(loc.Latitude-u,loc.Longitude-u)});
        }
Exemplo n.º 28
0
        private async void searchPane_QuerySubmitted(SearchBox sender, SearchBoxQuerySubmittedEventArgs args)
        {
            //throw new NotImplementedException();
            myMap.Children.Clear();
            
            //Logic for geaocding the query text
            if (!string.IsNullOrWhiteSpace(args.QueryText))
            {

              await new  MessageDialog(args.QueryText).ShowAsync();
                Uri geocodeUri = new Uri(
                    string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&c={1}&key={2}",
                    Uri.EscapeUriString(args.QueryText), args.Language, myMap.Credentials));

                //Get response from Bing Maps REST services
                Response r = await GetResponse(geocodeUri);

                if(r != null &&
                    r.ResourceSets != null &&
                    r.ResourceSets.Length > 0 &&
                    r.ResourceSets[0].Resources != null &&
                    r.ResourceSets[0].Resources.Length > 0)
                {
                    LocationCollection locations = new LocationCollection();

                    int i = 1;
                    foreach(BingMapsRESTService.Common.JSON.Location l
                                in r.ResourceSets[0].Resources)
                    {
                        //Get the Location of each result 
                        Bing.Maps.Location location = new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);
                        //Create a pushpin each location 
                        Pushpin pin = new Pushpin()
                        {
                            Tag = l.Name,
                            Text = i.ToString()
                        };
                        i++;

                        //Add a tapped event that will displau the name of the location
                        pin.Tapped += async (s, a) =>
                            {
                                var p = s as Pushpin;
                                await new MessageDialog(p.Tag as string).ShowAsync();
                            };
                        //Set the location of the pushpin
                        MapLayer.SetPosition(pin, location);

                        //add th pushpin to the map
                        myMap.Children.Add(pin);

                        //Add the coordinates of the location to a location collection
                        locations.Add(location);
                    }//End foreach
                    
                        //set the map view based on the location collection
                    myMap.SetView(new LocationRect(locations));
                }//End IF
                else 
                {
                    await new MessageDialog("Nenhum resultado encontrado..").ShowAsync();
                }

                    
                }
            }
Exemplo n.º 29
0
    private async void SetRoute(Location startLocation, Location endLocation)
    {
      ClearMap();
      //Create the Request URL for the routing service
      const string request =
        @"http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0={0},{1}&wp.1={2},{3}&rpo=Points&key={4}";

      var routeRequest =
        new Uri(string.Format(request, startLocation.Latitude, startLocation.Longitude, endLocation.Latitude,
                              endLocation.Longitude, _mapTrucks.Credentials));

      //Make a request and get the response
      var r = await GetResponse(routeRequest);

      if (r != null &&
          r.ResourceSets != null &&
          r.ResourceSets.Length > 0 &&
          r.ResourceSets[0].Resources != null &&
          r.ResourceSets[0].Resources.Length > 0)
      {
        var route = r.ResourceSets[0].Resources[0] as Route;
        if (route == null) return;

        //Get the route line data
        var routePath = route.RoutePath.Line.Coordinates;
        var locations = new LocationCollection();

        foreach (var t in routePath)
        {
          if (t.Length >= 2)
          {
            locations.Add(new Location(t[0], t[1]));
          }
        }

        //Create a MapPolyline of the route and add it to the map
        var routeLine = new MapPolyline
          {
            Color = Colors.Blue,
            Locations = locations,
            Width = 5
          };

        _routeLayer.Shapes.Add(routeLine);

        //Add start and end pushpins
        var start = new Pushpin
          {
            Text = "S",
            Background = new SolidColorBrush(Colors.Green)
          };

        _mapTrucks.Children.Add(start);
        MapLayer.SetPosition(start,
                             new Location(route.RouteLegs[0].ActualStart.Coordinates[0],
                                          route.RouteLegs[0].ActualStart.Coordinates[1]));

        var end = new Pushpin
          {
            Text = "E",
            Background = new SolidColorBrush(Colors.Red)
          };

        _mapTrucks.Children.Add(end);
        MapLayer.SetPosition(end,
                             new Location(route.RouteLegs[0].ActualEnd.Coordinates[0],
                                          route.RouteLegs[0].ActualEnd.Coordinates[1]));

        //Set the map view for the locations
        var locationRect = new LocationRect(locations);
        locationRect.Width += 0.5;
        locationRect.Height += 0.5;
        _mapTrucks.SetView(locationRect);
      }
    }
Exemplo n.º 30
0
        // Tapped on omniBox
        private void listBoxHandler(object sender, TappedRoutedEventArgs e)
        {
            int selectedIndex = listBox.SelectedIndex;
            listBox.Visibility = Visibility.Collapsed;
            controlsBG.Visibility = Visibility.Visible;
            controlsBG2.Visibility = Visibility.Collapsed;
            try
            {
                int ko = 0; // couter
                int start; // first no-hashtag symbol in string
                string pos = "";
                int counter = -1;
                while (ko < datalines.Length)
                {
                    ko++;
                    // Print in sourse/aim lable adress
                    if (((start = datalines[ko - 1].IndexOf("<text>")) != -1))
                    {
                        counter++;
                        if (counter != selectedIndex) continue;
                        int nameLeng = datalines[ko - 1].Length;
                        textBox.Text = "";
                        if (!isSourseTapped)
                            sourseLable.Text = datalines[ko - 1].Substring(start + 6, nameLeng - 6 - start - 7);
                        else
                            aimLable.Text = datalines[ko - 1].Substring(start + 6, nameLeng - 6 - start - 7);
                    }
                    // Start contextPerform()
                    if (((start = datalines[ko - 1].IndexOf("<pos>")) != -1) && (counter == selectedIndex))
                    {
                        int posLenght = datalines[ko - 1].Length;
                        pos = datalines[ko - 1].Substring(start + 5, posLenght - 5 - start - 6);

                        double l1 = Convert.ToDouble(pos.Substring(0, pos.IndexOf('.')) + "," + pos.Substring(pos.IndexOf('.') + 1, pos.IndexOf(' ') - pos.IndexOf('.') - 1));

                        double l2 = Convert.ToDouble(pos.Substring(pos.IndexOf(' ') + 1, pos.IndexOf('.', pos.IndexOf('.') + 1) - pos.IndexOf(' ') - 1)
                                + ',' +
                                    pos.Substring(pos.IndexOf('.', pos.IndexOf('.') + 1) + 1, pos.Length - (pos.IndexOf('.', pos.IndexOf('.') + 1) + 1)));

                        
                        myMap.SetView(location = new Bing.Maps.Location() { Latitude = l2, Longitude = l1 });
                        contextPerform();
                        break;
                    }
                }
            }
            catch { MessageDialog dialog = new MessageDialog("Возникла непредвиденная ошибка. Очистите карту и попробуйте построить маршрут снова. Если ошибка повторится, сообщите нам о ней через форму обратной связи.", "Ошибка #007001"); }
        }
Exemplo n.º 31
0
        private void SetRouteOnMap(LondonBicycles.Data.Models.Point myLocation, LondonBicycles.Data.Models.Point destination)
        {
            LocationCollection wayPoints = new LocationCollection();
            Bing.Maps.Location startWaypoint = new Bing.Maps.Location(myLocation.Latitude, myLocation.Longitude);
            Bing.Maps.Location endWaypoint = new Bing.Maps.Location(destination.Latitude, destination.Longitude);
            wayPoints.Add(startWaypoint);

            foreach (var routePoint in this.route.RoutePoints)
            {
                Bing.Maps.Location wayPoint = new Bing.Maps.Location()
                {
                    Latitude = routePoint.Latitude,
                    Longitude = routePoint.Longitude
                };

                wayPoints.Add(wayPoint);
            }

            wayPoints.Add(endWaypoint);

            DrawRoute(wayPoints);
            DrawPin.SetMyLocationPin(startWaypoint, this.map);
            DrawPin.SetStationPin(endWaypoint, this.map);
            this.GenerateGpx(myLocation, destination);
        }
Exemplo n.º 32
0
        private void GeocodeResultSelected(object sender, SelectionChangedEventArgs e)
        {
            var listBox = sender as ListBox;

            if (listBox.SelectedItems.Count > 0)
            {
                //Get the Selected Item
                var item = listBox.Items[listBox.SelectedIndex]
                           as BingMapsRESTService.Common.JSON.Location;

                //Get the items location
                Bing.Maps.Location location =
                       new Bing.Maps.Location(item.Point.Coordinates[0], item.Point.Coordinates[1]);

                //Zoom into the location
                MyMap.SetView(location, 18);
            }
        }
        private async Task<Bing.Maps.Location> GeocodePlaceName(string place)
        {
            Bing.Maps.Location geocodedPlace = new Bing.Maps.Location();
            
            GeocodeRequest geocodeRequest = new GeocodeRequest();
            geocodeRequest.Credentials = new Credentials();
            geocodeRequest.Credentials.ApplicationId = BING_MAPS_KEY;

            geocodeRequest.Query = place;
            GeocodeServiceClient geocodeService = new GeocodeServiceClient(
                GeocodeServiceClient.EndpointConfiguration.BasicHttpBinding_IGeocodeService);
            GeocodeResponse geocodeResponse = await geocodeService.GeocodeAsync(geocodeRequest);

            if (geocodeResponse.Results.Count > 0)
            {
                geocodedPlace.Latitude = geocodeResponse.Results[0].Locations[0].Latitude;
                geocodedPlace.Longitude = geocodeResponse.Results[0].Locations[0].Longitude;
            }

            return geocodedPlace;
        }
Exemplo n.º 34
0
        private async void GeocodeBtn_Click(object sender, RoutedEventArgs e)
        {
            ClearMap();

            string query = GeocodeTbx.Text;

            if (!string.IsNullOrWhiteSpace(query))
            {
                //Create the request URL for the Geocoding service
                Uri geocodeRequest = new Uri(
                    string.Format("http://dev.virtualearth.net/REST/v1/Locations?q={0}&key={1}",
                    query, MyMap.Credentials));

                //Make a request and get the response
                Response r = await GetResponse(geocodeRequest);

                if (r != null &&
                    r.ResourceSets != null &&
                    r.ResourceSets.Length > 0 &&
                    r.ResourceSets[0].Resources != null &&
                    r.ResourceSets[0].Resources.Length > 0)
                {
                    LocationCollection locations = new LocationCollection();

                    int i = 1;

                    foreach (BingMapsRESTService.Common.JSON.Location l
                             in r.ResourceSets[0].Resources)
                    {
                        //Get the location of each result
                        Bing.Maps.Location location =
                              new Bing.Maps.Location(l.Point.Coordinates[0], l.Point.Coordinates[1]);

                        //Create a pushpin each location
                        Pushpin pin = new Pushpin()
                        {
                            Tag = l.Name,
                            Text = i.ToString()
                        };

                        i++;

                        //Add a tapped event that will display the name of the location
                        pin.Tapped += (s, a) =>
                        {
                            var p = s as Pushpin;
                            ShowMessage(p.Tag as string);
                        };

                        //Set the location of the pushpin
                        MapLayer.SetPosition(pin, location);

                        //Add the pushpin to the map
                        MyMap.Children.Add(pin);

                        //Add the coordinates of the location to a location collection
                        locations.Add(location);
                    }

                    //Set the map view based on the location collection
                    MyMap.SetView(new LocationRect(locations));

                    //Pass the results to the item source of the GeocodeResult ListBox
                    GeocodeResults.ItemsSource = r.ResourceSets[0].Resources;
                }
                else
                {
                    ShowMessage("No Results found.");
                }
            }
            else
            {
                ShowMessage("Invalid Geocode Input.");
            }
        }
Exemplo n.º 35
0
        async void MapView_userPosChanged(object sender, Bing.Maps.Location l)
        {
            UpdateUserRadius("0.1", l);
            userLoc = l;
            MapShapeLayer layer = new MapShapeLayer();
            if (pathLocations != null)
            {
                foreach (Bing.Maps.Location loc in pathLocations)
                {
                    if (inRadius(loc, l, 0.05))
                    {
                        insideRoute = true;
                        showWarn = false;
                        break;
                    }
                    else
                        if (!inRadius(loc, l, 0.05))
                        {

                            insideRoute = false;
                        }

                }
            }
            if(insideRoute == false && showWarn == false)
            {
                ResourceLoader rl = new ResourceLoader();
                mapView.popup = new Windows.UI.Popups.MessageDialog(rl.GetString("OffRoutePopup"), "Route");
                mapView.popup.Commands.Add(new UICommand(rl.GetString("Ok"), new UICommandInvokedHandler(this.CommandInvokedHandler)));
                showWarn = true;
                await mapView.popup.ShowAsync();
            }           
            
            //if (Route != null)
            //{
            //    if (userRadius.Intersects(Route.Bounds) && Route != null)
            //    {
            //        insideRoute = true;
            //    }
            //    else
            //        if (!userRadius.Intersects(Route.Bounds))
            //        {
            //            ResourceLoader rl = new ResourceLoader();
            //            mapView.popup = new Windows.UI.Popups.MessageDialog(rl.GetString("OffRoutePopup"), "Route");

            //            await mapView.popup.ShowAsync();
            //            insideRoute = false;
            //        }
            //}
        }
Exemplo n.º 36
0
        private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
        {

            selectedphoto = e.NavigationParameter as PrismDemo.Models.Location;

            var fence = new Ellipse()
            {

                Fill = new SolidColorBrush(Colors.Blue),
                Stroke = new SolidColorBrush(Colors.White),
                StrokeThickness = 3,
                Width = 25,
                Height = 25,
               
            };

            TextBlock text = new TextBlock();
            text.FontSize = 20;
            text.Width = 200;
            text.TextWrapping = TextWrapping.Wrap;
            text.Text = selectedphoto.title;
            text.Foreground = new SolidColorBrush( Colors.Black);
            text.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Center;
            text.TextAlignment = TextAlignment.Center;

            StackPanel stak = new StackPanel();
            stak.Children.Add(text);
            stak.Children.Add(fence);



            Bing.Maps.Location locationpos = new Bing.Maps.Location(selectedphoto.latitude, selectedphoto.longitude);
            map1.SetView(locationpos, 16);

            map1.Children.Add(stak);

            MapLayer.SetPosition(stak, locationpos);
                        
        }
Exemplo n.º 37
0
        async private Task DrawPath()
        {
            loading.Visibility = Visibility.Visible;
            // form and send request
            string tmpSourseLoc = Convert.ToString(sourseLocation.Latitude).Substring(0, Convert.ToString(sourseLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Latitude).Substring(Convert.ToString(sourseLocation.Latitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Latitude).Length - Convert.ToString(sourseLocation.Latitude).IndexOf(',') - 1);
            tmpSourseLoc += "," + Convert.ToString(sourseLocation.Longitude).Substring(0, Convert.ToString(sourseLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Longitude).Substring(Convert.ToString(sourseLocation.Longitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Longitude).Length - Convert.ToString(sourseLocation.Longitude).IndexOf(',') - 1);
            string tmpAimLoc = Convert.ToString(AimLocation.Latitude).Substring(0, Convert.ToString(AimLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Latitude).Substring(Convert.ToString(AimLocation.Latitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Latitude).Length - Convert.ToString(AimLocation.Latitude).IndexOf(',') - 1);
            tmpAimLoc += "," + Convert.ToString(AimLocation.Longitude).Substring(0, Convert.ToString(AimLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Longitude).Substring(Convert.ToString(AimLocation.Longitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Longitude).Length - Convert.ToString(AimLocation.Longitude).IndexOf(',') - 1);
            var url = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" +
                        tmpSourseLoc +
                        "&wp.1=" +
                        tmpAimLoc +
                        "&optmz=distance&rpo=Points&key=" + "2YNtFFMLLBJhNArw7AGF~J1bD5V8AXTm26ao0o20rRw~AqSRI8WDH0Mx820MLWME4SM-ye-FewEHmO7vj5O4vSDrNdVWsnRXo3I-LUhllJrB";
             Uri geocodeRequest = new Uri(url);
            BingMapHelper.Response r = await GetResponse(geocodeRequest);

            if (r.StatusCode != 404)
            {
                // Delete lables from map
                myMap.Children.Clear();
                myMap.ShapeLayers.Clear();

                // Draw Path via server answer 
                geolocator = new Geolocator();
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Color = Windows.UI.Colors.RoyalBlue;
                routeLine.Width = 6.0;

                int bound = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);

                sourseLocation.Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][0];
                sourseLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][1];

                AimLocation.Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][0];
                AimLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][1];

                var sourceLocation = new Bing.Maps.Location(sourseLocation.Latitude, sourseLocation.Longitude);
                myMap.Children.Add(pin);
                myMap.Children.Add(pinAim);

                var destinationLocation = new Bing.Maps.Location(AimLocation.Latitude, AimLocation.Longitude);
                myMap.SetView(sourceLocation, myMap.ZoomLevel);
                for (int i = 0; i < bound; i++)
                {
                    routeLine.Locations.Add(new Location
                        {
                            Latitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
                            Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
                        });
                }
                MapShapeLayer shapeLayer = new MapShapeLayer();
                shapeLayer.Shapes.Add(routeLine);
                myMap.ShapeLayers.Add(shapeLayer);
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Маршрут построить не удалось. Попробуйте снова. \r\nЕсли ошибка повторится вновь, просим уведомить нас о ней через форму обратной связи.", "Ошибка построения маршрута #007100");
                await dialog.ShowAsync();
            }
            loading.Visibility = Visibility.Collapsed;
        }
Exemplo n.º 38
0
        async private Task DrawPath()
        {
            loading.Visibility = Visibility.Visible;
            // form and send request
            string tmpSourseLoc = Convert.ToString(sourseLocation.Latitude).Substring(0, Convert.ToString(sourseLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Latitude).Substring(Convert.ToString(sourseLocation.Latitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Latitude).Length - Convert.ToString(sourseLocation.Latitude).IndexOf(',') - 1);

            tmpSourseLoc += "," + Convert.ToString(sourseLocation.Longitude).Substring(0, Convert.ToString(sourseLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(sourseLocation.Longitude).Substring(Convert.ToString(sourseLocation.Longitude).IndexOf(',') + 1, Convert.ToString(sourseLocation.Longitude).Length - Convert.ToString(sourseLocation.Longitude).IndexOf(',') - 1);
            string tmpAimLoc = Convert.ToString(AimLocation.Latitude).Substring(0, Convert.ToString(AimLocation.Latitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Latitude).Substring(Convert.ToString(AimLocation.Latitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Latitude).Length - Convert.ToString(AimLocation.Latitude).IndexOf(',') - 1);

            tmpAimLoc += "," + Convert.ToString(AimLocation.Longitude).Substring(0, Convert.ToString(AimLocation.Longitude).IndexOf(',')) + '.' + Convert.ToString(AimLocation.Longitude).Substring(Convert.ToString(AimLocation.Longitude).IndexOf(',') + 1, Convert.ToString(AimLocation.Longitude).Length - Convert.ToString(AimLocation.Longitude).IndexOf(',') - 1);
            var url = "http://dev.virtualearth.net/REST/V1/Routes/Driving?o=json&wp.0=" +
                      tmpSourseLoc +
                      "&wp.1=" +
                      tmpAimLoc +
                      "&optmz=distance&rpo=Points&key=" + "2YNtFFMLLBJhNArw7AGF~J1bD5V8AXTm26ao0o20rRw~AqSRI8WDH0Mx820MLWME4SM-ye-FewEHmO7vj5O4vSDrNdVWsnRXo3I-LUhllJrB";
            Uri geocodeRequest = new Uri(url);

            BingMapHelper.Response r = await GetResponse(geocodeRequest);

            if (r.StatusCode != 404)
            {
                // Delete lables from map
                myMap.Children.Clear();
                myMap.ShapeLayers.Clear();

                // Draw Path via server answer
                geolocator = new Geolocator();
                MapPolyline routeLine = new MapPolyline();
                routeLine.Locations = new LocationCollection();
                routeLine.Color     = Windows.UI.Colors.RoyalBlue;
                routeLine.Width     = 6.0;

                int bound = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates.GetUpperBound(0);

                sourseLocation.Latitude  = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][0];
                sourseLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[0][1];

                AimLocation.Latitude  = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][0];
                AimLocation.Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[bound][1];

                var sourceLocation = new Bing.Maps.Location(sourseLocation.Latitude, sourseLocation.Longitude);
                myMap.Children.Add(pin);
                myMap.Children.Add(pinAim);

                var destinationLocation = new Bing.Maps.Location(AimLocation.Latitude, AimLocation.Longitude);
                myMap.SetView(sourceLocation, myMap.ZoomLevel);
                for (int i = 0; i < bound; i++)
                {
                    routeLine.Locations.Add(new Location
                    {
                        Latitude  = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][0],
                        Longitude = ((BingMapHelper.Route)(r.ResourceSets[0].Resources[0])).RoutePath.Line.Coordinates[i][1]
                    });
                }
                MapShapeLayer shapeLayer = new MapShapeLayer();
                shapeLayer.Shapes.Add(routeLine);
                myMap.ShapeLayers.Add(shapeLayer);
            }
            else
            {
                MessageDialog dialog = new MessageDialog("Маршрут построить не удалось. Попробуйте снова. \r\nЕсли ошибка повторится вновь, просим уведомить нас о ней через форму обратной связи.", "Ошибка построения маршрута #007100");
                await dialog.ShowAsync();
            }
            loading.Visibility = Visibility.Collapsed;
        }