예제 #1
0
        private async void ReverseGeocode(object sender, System.Windows.Input.MouseEventArgs e)
        {
            BingMapsRESTToolkit.Coordinate coord = new BingMapsRESTToolkit.Coordinate();
            if (sender is Pushpin)
            {
                coord = LocationToCoordinate(((Pushpin)sender).Location);
            }
            if (sender is DragPin)
            {
                coord = LocationToCoordinate(((DragPin)sender).Location);
            }


            var response = await BingMapsRESTToolkit.ServiceManager.GetResponseAsync(new BingMapsRESTToolkit.ReverseGeocodeRequest()
            {
                IncludeEntityTypes = new List <BingMapsRESTToolkit.EntityType>()
                {
                    BingMapsRESTToolkit.EntityType.Address
                },
                BingMapsKey         = SESSION_KEY,
                IncludeIso2         = true,
                IncludeNeighborhood = true,
                Point = coord
            });

            if (response != null &&
                response.ResourceSets != null &&
                response.ResourceSets.Length > 0 &&
                response.ResourceSets[0].Resources != null &&
                response.ResourceSets[0].Resources.Length > 0)
            {
                var address = response.ResourceSets[0].Resources[0] as BingMapsRESTToolkit.Location;

                CurrentAddressLabel.Text = address.Address.FormattedAddress.ToString();
            }
        }
예제 #2
0
        public async void UpdateRoute(Location loc, DragPin fisrt, DragPin sec)
        {
            RouteLayer.Children.Clear();
            polylines.Clear();
            //var startCoord = LocationToCoordinate(fisrt.Location);
            //var endCoord = LocationToCoordinate(sec.Location);
            BingMapsRESTToolkit.Coordinate startCoord = null;
            BingMapsRESTToolkit.Coordinate endCoord   = null;


            if (Get_Other_DragPins.Count == 0)
            {
                // MessageBox.Show("зайшло коли ліст нуль");
                startCoord = LocationToCoordinate(Get_Start_DragPin.Location);
                endCoord   = LocationToCoordinate(Get_End_DragPin.Location);

                #region
                var response = await BingMapsRESTToolkit.ServiceManager.GetResponseAsync(new BingMapsRESTToolkit.RouteRequest()
                {
                    Waypoints = new List <BingMapsRESTToolkit.SimpleWaypoint>()
                    {
                        new BingMapsRESTToolkit.SimpleWaypoint(startCoord),
                        new BingMapsRESTToolkit.SimpleWaypoint(endCoord)
                    },
                    BingMapsKey  = SessionKey,
                    RouteOptions = new BingMapsRESTToolkit.RouteOptions()
                    {
                        RouteAttributes = new List <BingMapsRESTToolkit.RouteAttributeType>
                        {
                            //Be sure to return the route path information so that we can draw the route line.
                            BingMapsRESTToolkit.RouteAttributeType.RoutePath
                        }
                    }
                });

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

                    //Generate a Polyline from the route path information.
                    var locs = new LocationCollection();

                    for (var i = 0; i < route.RoutePath.Line.Coordinates.Length; i++)
                    {
                        locs.Add(new Location(route.RoutePath.Line.Coordinates[i][0], route.RoutePath.Line.Coordinates[i][1]));
                    }

                    var routeLine = new MapPolyline()
                    {
                        Locations       = locs,
                        Stroke          = new SolidColorBrush(Colors.Blue),
                        StrokeThickness = 3
                    };

                    polylines.Add(routeLine);

                    foreach (MapPolyline a in polylines)
                    {
                        RouteLayer.Children.Add(a);
                    }
                }
                #endregion
            }
            else
            {
                // MessageBox.Show("зайшло коли ліст не нуль");
                for (int j = 0; j <= Get_Other_DragPins.Count; j++)
                {
                    if (j == 0)
                    {
                        // MessageBox.Show("зайшло будує від першого до того шо додав" + "j=" + j);
                        startCoord = LocationToCoordinate(Get_Start_DragPin.Location);
                        endCoord   = LocationToCoordinate(Get_Other_DragPins[0].Location);
                    }
                    else if (j == Get_Other_DragPins.Count)
                    {
                        //MessageBox.Show("зайшло будує від того шо додав до останнього");
                        startCoord = LocationToCoordinate(Get_Other_DragPins[Get_Other_DragPins.Count - 1].Location);
                        endCoord   = LocationToCoordinate(Get_End_DragPin.Location);
                    }
                    if (j != 0 && j != Get_Other_DragPins.Count)
                    {
                        startCoord = LocationToCoordinate(Get_Other_DragPins[j - 1].Location);
                        endCoord   = LocationToCoordinate(Get_Other_DragPins[j].Location);
                    }

                    #region  draw
                    var response = await BingMapsRESTToolkit.ServiceManager.GetResponseAsync(new BingMapsRESTToolkit.RouteRequest()
                    {
                        Waypoints = new List <BingMapsRESTToolkit.SimpleWaypoint>()
                        {
                            new BingMapsRESTToolkit.SimpleWaypoint(startCoord),
                            new BingMapsRESTToolkit.SimpleWaypoint(endCoord)
                        },
                        BingMapsKey  = SessionKey,
                        RouteOptions = new BingMapsRESTToolkit.RouteOptions()
                        {
                            RouteAttributes = new List <BingMapsRESTToolkit.RouteAttributeType>
                            {
                                //Be sure to return the route path information so that we can draw the route line.
                                BingMapsRESTToolkit.RouteAttributeType.RoutePath
                            }
                        }
                    });

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

                        //Generate a Polyline from the route path information.
                        var locs = new LocationCollection();

                        for (var i = 0; i < route.RoutePath.Line.Coordinates.Length; i++)
                        {
                            locs.Add(new Location(route.RoutePath.Line.Coordinates[i][0], route.RoutePath.Line.Coordinates[i][1]));
                        }

                        var routeLine = new MapPolyline()
                        {
                            Locations       = locs,
                            Stroke          = new SolidColorBrush(Colors.Blue),
                            StrokeThickness = 3
                        };
                        polylines.Add(routeLine);
                        //MessageBox.Show(polylines.Count.ToString());

                        // RouteLayer.Children.Add(polylines[0]);
                    }

                    /*foreach (MapPolyline a in polylines)
                     * {
                     *  RouteLayer.Children.Add(a);
                     * // MessageBox.Show(polylines.Count.ToString());
                     * }*/

                    #endregion
                }
                try
                {
                    foreach (MapPolyline a in polylines)
                    {
                        RouteLayer.Children.Add(a);
                        // MessageBox.Show(polylines.Count.ToString());
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.ToString());
                }
            }

            //Calculate a route between the start and end pushpin.
        }