private async void BusSearchTest() { BusRouteSearchOption rgo = new BusRouteSearchOption(); rgo.X1 = 116.4604213; rgo.Y1 = 39.9204703; rgo.X2 = 116.2883602; rgo.Y2 = 39.8236433; rgo.CityCode = "010"; BusRouteSearchResult rgcs = await BusRouteSearch.BusRouteSearchWithOption(rgo); if (rgcs.Erro == null) { Debug.WriteLine(rgcs); } else { Debug.WriteLine(rgcs.Erro.Message); } }
/// <summary> /// Invoked when this page is about to be displayed in a Frame. /// </summary> /// <param name="e">Event data that describes how this page was reached. The Parameter /// property is typically used to configure the page.</param> private async void BusRouteSearchClick(object sender, RoutedEventArgs e) { String startPosition = startInput.Text; POISearchOption p = new POISearchOption(); p.SearchName = startInput.Text; p.CityCode = cityInput.Text; POISearchResult iopStart = await POISearch.PoiSearchWithOption(p); Double Startx = new double(); Double Endx = new double(); Double Starty = new double(); Double Endy = new double(); ALngLat lnglatStart; if (iopStart.Erro == null) { foreach (POI poi in iopStart.POIs) { poi.Name = poi.Name; Startx = poi.X; Starty = poi.Y; ALngLat lnglat = new ALngLat(poi.X, poi.Y); AMarker poiMarker = new AMarker(); poiMarker.LngLat = lnglat; ATip tip = new ATip(); tip.Title = poi.Name; tip.ContentText = poi.Address; poiMarker.TipFrameworkElement = tip; map.Children.Add(poiMarker); break; } } else { MessageDialog msd = new MessageDialog("起点输入有误,请重新输入!", "提示"); msd.ShowAsync(); } String endPosition = endInput.Text; p.SearchName = endInput.Text; p.CityCode = cityInput.Text; POISearchResult iopEnd = await POISearch.PoiSearchWithOption(p); if (iopEnd.Erro == null) { foreach (POI poi in iopEnd.POIs) { poi.Name = poi.Name; Endx = poi.X; Endy = poi.Y; ALngLat lnglat = new ALngLat(poi.X, poi.Y); AMarker poiMarker = new AMarker(); poiMarker.LngLat = lnglat; ATip tip = new ATip(); tip.Title = poi.Name; tip.ContentText = poi.Address; poiMarker.TipFrameworkElement = tip; map.Children.Add(poiMarker); break; } } else { MessageDialog msd = new MessageDialog("终点输入有误,请重新输入!", "提示"); msd.ShowAsync(); } BusRouteSearchOption rgo = new BusRouteSearchOption(); rgo.X1 = Startx; rgo.Y1 = Starty; rgo.X2 = Endx; rgo.Y2 = Endy; rgo.CityCode = "010"; BusRouteSearchResult rgcs = await BusRouteSearch.BusRouteSearchWithOption(rgo); if (rgcs.Erro == null) { Debug.WriteLine(rgcs); } else { Debug.WriteLine(rgcs.Erro.Message); } }
private async void BusRouteSearchTest(string cityCode, string searchName, string searchEndName) { POISearchOption ps = new POISearchOption(); ps.SearchName = searchName; ps.CityCode = cityCode; POISearchOption pe = new POISearchOption(); pe.SearchName = searchEndName; pe.CityCode = cityCode; POISearchResult iopStart = await POISearch.PoiSearchWithOption(ps); //查询起点坐标 POISearchResult iopEnd = await POISearch.PoiSearchWithOption(pe); //查询终点坐标 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); BusRouteSearchOption rgo = new BusRouteSearchOption(); rgo.X1 = poist.X; rgo.Y1 = poist.Y; rgo.X2 = poied.X; rgo.Y2 = poied.Y; rgo.CityCode = cityCode; BusRouteSearchResult rgcs = await BusRouteSearch.BusRouteSearchWithOption(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, () => { markLayer.Children.Clear(); ALngLat lnglat = new ALngLat(poist.X, poist.Y); AMarker poiMarker = new AMarker(); poiMarker.IconURI = new Uri("/Samples/qd.png", UriKind.Relative); poiMarker.LngLat = lnglat; ATip tip = new ATip(); tip.Title = poist.Name; tip.ContentText = poist.Address; poiMarker.TipFrameworkElement = tip; markLayer.Children.Add(poiMarker); 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; markLayer.Children.Add(poiMarkered); ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标 APolyline pol = new APolyline(); pol.LineThickness = 5; IEnumerable <Bus> busInfo = rgcs.Routes; IEnumerable <String> lnglatstring; IEnumerable <String> passdeportstring; //画公交线路和公交站点 foreach (Bus bus in busInfo) { IEnumerable <BusSegment> bussegmentInfo = bus.SegmentArray; foreach (BusSegment bs in bussegmentInfo) { lnglatstring = bs.CoordinateList.Split(new Char[] { ';' }); passdeportstring = bs.PassDeportCoordinate.Split(new Char[] { ';' }); String[] passport = bs.PassDeportName.Split(' '); int i = 0; foreach (String ss in lnglatstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]))); } foreach (String ss in passdeportstring) { String[] lnglatds = ss.Split(new Char[] { ',' }); ALngLat lnglatpassdeport = new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])); ATip tipStart = new ATip(); // tipStart.Anchor = new Point(0,1); tipStart.Title = passport[i]; AMarker marker = new AMarker(); marker.Anchor = new Point(0.46, 1); marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/bx11.png"); marker.LngLat = lnglatpassdeport; marker.TipFrameworkElement = tipStart; markLayer.Children.Add(marker); // Canvas.SetTop(marker,100); marker.TipAnchor = new Point(0.35, 1); } } break; } pol.LngLats = lnglatRoute; markLayer.Children.Insert(0, pol); map.SetOverlaysFitView(); }); } }