Exemple #1
0
        private async void DriveRouteSearchTest(string cityCode, string searchName, string searchEndName)
        {
            POISearchOption pst = new POISearchOption();

            pst.SearchName = searchName;
            pst.CityCode   = cityCode;
            POISearchOption ped = new POISearchOption();

            ped.SearchName = searchEndName;
            ped.CityCode   = cityCode;

            POISearchResult iopStart = await POISearch.PoiSearchWithOption(pst); //查起点坐标

            POISearchResult iopEnd = await POISearch.PoiSearchWithOption(ped);   //查终点坐标

            if (iopStart.Erro != null || iopStart.POIs == null)
            {
                MessageDialog msd = new MessageDialog(iopStart.Erro.Message);
                this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    msd.ShowAsync();
                });
                return;
            }
            if (iopEnd.Erro != null || iopEnd.POIs == null)
            {
                MessageDialog msd = new MessageDialog(iopStart.Erro.Message);
                this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    msd.ShowAsync();
                });
                return;
            }
            POI poist = Enumerable.First <POI>(iopStart.POIs);
            POI poied = Enumerable.First <POI>(iopEnd.POIs);


            RouteSearchOption rgo = new RouteSearchOption();

            rgo.X1 = poist.X;
            rgo.Y1 = poist.Y;
            rgo.X2 = poied.X;
            rgo.Y2 = poied.Y;
            RouteSearchResult rgcs = await RouteSearch.RouteSearchWithOption(rgo);

            if (rgcs.Erro != null)
            {
                MessageDialog msd = new MessageDialog("查询公交失败!" + rgcs.Erro.Message, "提示");
                this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                {
                    msd.ShowAsync();
                });
                return;
            }
            else
            {
                this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
                {
                    ALngLat lnglatst                = new ALngLat(poist.X, poist.Y);
                    AMarker poiMarkerst             = new AMarker();
                    poiMarkerst.IconURI             = new Uri("/Samples/qd.png", UriKind.Relative);
                    poiMarkerst.LngLat              = lnglatst;
                    ATip tipst                      = new ATip();
                    tipst.Title                     = poist.Name;
                    tipst.ContentText               = poist.Address;
                    poiMarkerst.TipFrameworkElement = tipst;
                    map.Children.Add(poiMarkerst);


                    ALngLat lnglated                = new ALngLat(poied.X, poied.Y);
                    AMarker poiMarkered             = new AMarker();
                    poiMarkered.IconURI             = new Uri("/Samples/zd.png", UriKind.Relative);
                    poiMarkered.LngLat              = lnglated;
                    ATip tiped                      = new ATip();
                    tiped.Title                     = poied.Name;
                    tiped.ContentText               = poied.Address;
                    poiMarkered.TipFrameworkElement = tiped;
                    map.Children.Add(poiMarkered);

                    APolyline pol     = new APolyline();
                    pol.LineThickness = 5;
                    ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标

                    IEnumerable <String> lnglatstring;
                    IEnumerable <RouteSegment> rsegment = rgcs.Segment;
                    foreach (RouteSegment rs in rsegment)
                    {
                        lnglatstring = rs.Coor.Split(new Char[] { ';' });
                        foreach (String ss in lnglatstring)
                        {
                            String[] lnglatds = ss.Split(new Char[] { ',' });
                            lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])));
                        }
                    }
                    pol.LngLats = lnglatRoute;
                    markLayer.Children.Add(pol);
                    map.SetOverlaysFitView();
                });
            }
        }
Exemple #2
0
        private async void driveroute()
        {
            RouteSearchOption rgo = new RouteSearchOption();
            rgo.X1 = marker.LngLat.LngX;
            rgo.Y1 = marker.LngLat.LatY;
            rgo.X2 = marker2.LngLat.LngX;
            rgo.Y2 = marker2.LngLat.LatY;

            APolyline pol = new APolyline();
            pol.LineThickness = 5;
            ObservableCollection<ALngLat> lnglatRoute = new ObservableCollection<ALngLat>();    //线路坐标
            lnglatRoute.Add(new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY));
            RouteSearchResult rgcs = await RouteSearch.RouteSearchWithOption(rgo);
            IEnumerable<String> lnglatstring;
            IEnumerable<RouteSegment> rsegment = rgcs.Segment;
            foreach (RouteSegment rs in rsegment)
            {
                lnglatstring = rs.Coor.Split(new Char[] { ';' });
                foreach (String ss in lnglatstring)
                {
                    String[] lnglatds = ss.Split(new Char[] { ',' });
                    lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])));
                }
            }

            pol.LngLats = lnglatRoute;
            markLayer.Children.Clear();
            markLayer.Children.Add(pol);
            map.SetOverlaysFitView();
            //map.SetZoomAndCenter(Convert.ToInt32(marker2.LngLat.LngX-marker.LngLat.LngX),map.Center);
        }