async void CenterlnglatAroundPOISearch(string cityCode, int number, string searchName)
        {
            DateTime        st = DateTime.Now;
            POISearchOption p  = new POISearchOption();

            p.CityCode = cityCode;
            //  p.SrcType = dataTypeInput.SelectedItem;
            p.SrcType    = GetValue;
            p.Number     = number;
            p.Sid        = "1005"; //服务编码 默s认为1000-关键字查询 1001-根据中心点关键字查询周边兴趣点 1002-根据中心点坐标查询周边兴趣点 1005-以拉框方式查询图形区域内的关键字信息.
            p.SearchName = searchName;
            p.Region     = "116.3544845,39.98882653;116.37010574,39.89722607;116.3544845,39.89722607;116.37010574,39.98882653";
            p.RegionType = "polygon";

            POISearchResult iop = await POISearch.PoiSearchWithOption(p);

            //   POISearchResult iop = await POISearch.PoiSearchByRegionAndKeyword("中关村", "116.204,39.9938;116.456,39.8833", "rectangle", 10);
            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                if (iop.Erro == null && iop.POIs != null)
                {
                    TimeSpan elapsedSpan = new TimeSpan(DateTime.Now.Ticks - st.Ticks);
                    int i = 0;
                    SearchTextGrid.Visibility = Visibility.Collapsed;
                    Debug.WriteLine(iop);
                    foreach (POI poi in iop.POIs)
                    {
                        i++;
                        poi.Name                      = "  " + i + "、" + poi.Name;
                        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;
                        markerList1.Add(poiMarker);
                        map.Children.Add(poiMarker);
                    }
                    PoiListView.DataContext = iop.POIs;
                    map.SetOverlaysFitView();
                    PoiListView.SelectedIndex = 0;
                    markerList1[0].OpenTip();
                    PoiListView.Visibility = Visible;
                }
                else
                {
                    MessageDialog msd = new MessageDialog(iop.Erro.Message);
                    this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        msd.ShowAsync();
                    });
                    Debug.WriteLine(iop.Erro.Message);
                }
            });

            //  POISearchResult poiResult = POISearch.PoiSearchByRegionAndKeyword("酒店",lnglats,"Polygon",10);
        }
        async void CenterlnglatAroundPOISearch(string searchName, string cityCode, double x, double y, int range, int number)
        {
            DateTime        st = DateTime.Now;
            POISearchOption p  = new POISearchOption();

            p.CityCode = cityCode;
            //  p.SrcType = dataTypeInput.SelectedItem;
            p.SrcType    = GetValue;
            p.CenX       = x;
            p.CenY       = y;
            p.Range      = range;
            p.Number     = number;
            p.Sid        = "1002"; //服务编码 默认为1000-关键字查询 1001-根据中心点关键字查询周边兴趣点 1002-根据中心点坐标查询周边兴趣点 1005-以拉框方式查询图形区域内的关键字信息.
            p.SearchName = searchName;


            POISearchResult iop = await POISearch.PoiSearchWithOption(p);

            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                if (iop.Erro == null)
                {
                    TimeSpan elapsedSpan = new TimeSpan(DateTime.Now.Ticks - st.Ticks);
                    int i = 0;
                    SearchTextGrid.Visibility = Visibility.Collapsed;
                    Debug.WriteLine(iop);

                    PoiListView.DataContext = iop.POIs;
                    foreach (POI poi in iop.POIs)
                    {
                        i++;
                        poi.Name                      = "  " + i + "、" + poi.Name;
                        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;
                        markerList1.Add(poiMarker);
                        map.Children.Add(poiMarker);
                    }
                    map.SetOverlaysFitView();
                    PoiListView.SelectedIndex = 0;
                    markerList1[0].OpenTip();
                    PoiListView.Visibility = Visible;
                }
                else
                {
                    MessageDialog msd = new MessageDialog(iop.Erro.Message);
                    this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        msd.ShowAsync();
                    });
                    Debug.WriteLine(iop.Erro.Message);
                }
            });
        }
示例#3
0
        /// <summary>
        /// 添加标记物
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AddMarker(object sender, RoutedEventArgs e)
        {
            map.Children.Clear();
            AMarker poi = new AMarker();

            poi.LngLat  = map.Center;
            poi.IconURI = new Uri("http://api.amap.com/Home/Tpl/default/Public/Images/wp7.png");//也可以读本地图片
            map.Children.Add(poi);
        }
示例#4
0
        /// <summary>
        /// MarkerTIP上添加自定义容器
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AddCustomTipOnMarker(object sender, RoutedEventArgs e)
        {
            //自定义容器
            CustomOverlayControl coo = new CustomOverlayControl();
            AMarker marker           = new AMarker();

            marker.LngLat = map.Center;
            marker.TipFrameworkElement = coo;
            map.Children.Add(marker);
            marker.OpenTip();
        }
 private void PoiListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     if (pointma != null)
     {
         markLayer.Children.Remove(pointma);
     }
     markerList[PoiListView.SelectedIndex].IconURI = new Uri("http://api.amap.com/webapi/static/Images/point.png", UriKind.RelativeOrAbsolute);
     pointma = markerList[PoiListView.SelectedIndex];
     markLayer.Children.Add(pointma);
     markerList[PoiListView.SelectedIndex].OpenTip();
 }
        async void POISearchTest(string searchName, string cityCode, string srcType, int num)
        {
            DateTime st = DateTime.Now;
            //Debug.WriteLine(DateTime.Now.Ticks);
            POISearchOption p = new POISearchOption();

            p.SearchName = searchName;
            p.CityCode   = cityCode;
            p.SrcType    = srcType;
            p.Number     = num;
            //  p.Number = dataNumber.Value;
            POISearchResult iop = await POISearch.PoiSearchWithOption(p);

            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                if (iop.Erro == null)
                {
                    // POISearchResult iop = await POISearch.PoiSearchByRegionAndKeyword("中关村", "116.204,39.9938;116.456,39.8833", "rectangle", 10);
                    TimeSpan elapsedSpan = new TimeSpan(DateTime.Now.Ticks - st.Ticks);
                    int i = 0;
                    SearchTextGrid.Visibility = Visibility.Collapsed;
                    foreach (POI poi in iop.POIs)
                    {
                        i++;
                        poi.Name                      = "  " + i + "、" + poi.Name;
                        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;
                        markerList.Add(poiMarker);
                        map.Children.Add(poiMarker);
                    }
                    PoiListView.ItemsSource = iop.POIs;

                    map.SetOverlaysFitView();
                    PoiListView.SelectedIndex = 0;
                    markerList[0].OpenTip();
                    PoiListView.Visibility = Visible;
                }
                else
                {
                    MessageDialog msd = new MessageDialog(iop.Erro.Message);
                    this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        msd.ShowAsync();
                    });
                    Debug.WriteLine(iop.Erro.Message);
                }
            });
        }
示例#7
0
        /// <summary>
        /// 在Marker上添加信息窗口
        /// </summary>
        public void AddTipOnMarker(object sender, RoutedEventArgs e)
        {
            ATip tip = new ATip();

            tip.Title       = "我是标题";
            tip.ContentText = "我是内容";
            AMarker marker = new AMarker();

            marker.LngLat = map.Center;
            marker.TipFrameworkElement = tip;
            map.Children.Add(marker);
            marker.OpenTip();
        }
        private async void ReGeoCodeTest(double lng, double lat)
        {
            ReverseGeocodingOption rgo = new ReverseGeocodingOption();
            rgo.XCoors = new double[] { lng };
            rgo.YCoors = new double[] { lat };
            ReverseGeoCodingResult rgcs = await ReGeoCode.GeoCodeToAddressWithOption(rgo);
            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
      {
          if (rgcs.Erro == null && rgcs.resultList != null)
          {
              IEnumerable<ReverseGeocodingInfo> reverseGeocodeResult = rgcs.resultList;
              foreach (ReverseGeocodingInfo poi in reverseGeocodeResult)
              {
                  int i = 0;
                  foreach (POI poilist in poi.Pois)
                  {
                      i++;
                      AMarker marker = new AMarker();
                      marker.LngLat = new ALngLat(poilist.X, poilist.Y);
                      ATip tip = new ATip();
                      tip.Title = i + ": " + poilist.Name;
                      tip.ContentText = poilist.Address;
                      marker.TipFrameworkElement = tip;
                      markerList.Add(marker);
                      map.Children.Add(marker);

                  }

              }
              markerList[0].OpenTip();
              map.SetOverlaysFitView();

          }
          else
          {
              MessageDialog msd = new MessageDialog(rgcs.Erro.Message);
              this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
              {
                  msd.ShowAsync();
              });
          }
      });
        }
示例#9
0
        /// <summary>
        /// 添加左下角点
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            map.Children.Clear();
            lbmk = null;
            map.Children.Add(new AEllipse()
            {
                Anchor    = new Point(0.5, 0.5),
                RadiusX   = 8,
                RadiusY   = 8,
                FillColor = Colors.Brown,
                LngLat    = center,
            });

            if (lbmk == null)
            {
                map.Children.Add(lbmk = new AMarker()
                {
                    IconURI             = new Uri("/Samples/01.png", UriKind.RelativeOrAbsolute),
                    Anchor              = new Point(0, 1),
                    LngLat              = center,
                    TipFrameworkElement = new ATip()
                    {
                        Title = "左下角点", ContentText = "这是左下角点"
                    }
                });
            }
            else
            {
                map.Children.Remove(lbmk);
                map.Children.Add(lbmk = new AMarker()
                {
                    IconURI             = new Uri("/Samples/01.png", UriKind.RelativeOrAbsolute),
                    Anchor              = new Point(0, 1),
                    LngLat              = center,
                    TipFrameworkElement = new ATip()
                    {
                        Title = "左下角点", ContentText = "这是左下角点"
                    }
                });
            }
        }
示例#10
0
        public MapView()
        {
            this.InitializeComponent();

            this.Output.Children.Add(rootPage.map);

            AMarker marker = new AMarker();

            marker.LngLat  = rootPage.CurrentLocation;
            marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
            ATip tip = new ATip();

            tip.Title                  = "当前位置";
            tip.ContentText            = "Current Position";
            marker.TipFrameworkElement = tip;
            rootPage.map.Children.Add(marker);
            marker.OpenTip();

            if (rootPage.CurrentReminderStation != null)
            {
                this.GotoReminder.IsEnabled = true;
            }

            /*
             * if (rootPage.CurrentStation != null)
             * {
             *  foreach (StationFeature feature in rootPage.CurrentStation.response.resultSet.busLine.stationData.StationFeatures)
             *  {
             *      AMarker marker = new AMarker();
             *      marker.LngLat = new ALngLat(feature.longitude, feature.latitude);
             *      marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
             *      ATip tip = new ATip();
             *      tip.Title = "站点";
             *      tip.ContentText = feature.caption;
             *      marker.TipFrameworkElement = tip;
             *      rootPage.map.Children.Add(marker);
             *      marker.OpenTip();
             *  }
             * }
             * */
        }
示例#11
0
        public MapView()
        {
            this.InitializeComponent();

            this.Output.Children.Add(rootPage.map);

            AMarker marker = new AMarker();
            marker.LngLat = rootPage.CurrentLocation;
            marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
            ATip tip = new ATip();
            tip.Title = "当前位置";
            tip.ContentText = "Current Position";
            marker.TipFrameworkElement = tip;
            rootPage.map.Children.Add(marker);
            marker.OpenTip();

            if (rootPage.CurrentReminderStation != null)
            {
                this.GotoReminder.IsEnabled = true;
            }
    
            /*
            if (rootPage.CurrentStation != null)
            {
                foreach (StationFeature feature in rootPage.CurrentStation.response.resultSet.busLine.stationData.StationFeatures)
                {
                    AMarker marker = new AMarker();
                    marker.LngLat = new ALngLat(feature.longitude, feature.latitude);
                    marker.IconURI = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
                    ATip tip = new ATip();
                    tip.Title = "站点";
                    tip.ContentText = feature.caption;
                    marker.TipFrameworkElement = tip;
                    rootPage.map.Children.Add(marker);
                    marker.OpenTip();
                }
            }
             * */
        }
示例#12
0
        private async void GeoCodeTest()
        {
            GeoCodingOption rgo = new GeoCodingOption();

            rgo.Address = "北京市朝阳区望京阜通东大街方恒国际中心";
            GeoCodingResult rgcs = await GeoCode.AddressToGeoCodeWithOption(rgo);

            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                if (rgcs.Erro == null && rgcs.GeoCodingList != null)
                {
                    IEnumerable <GeoPOI> pois = rgcs.GeoCodingList;
                    int i = 0;
                    foreach (GeoPOI poi in pois)
                    {
                        i++;
                        ATip tip                   = new ATip();
                        tip.Title                  = poi.Name;
                        tip.ContentText            = poi.Address;
                        AMarker marker             = new AMarker();
                        marker.LngLat              = new ALngLat(poi.X, poi.Y);
                        marker.TipFrameworkElement = tip;
                        map.Children.Add(marker);
                        marker.OpenTip();
                        map.SetZoomAndCenter(18, marker.LngLat);
                    }
                    Debug.WriteLine(rgcs);
                }
                else
                {
                    MessageDialog msd = new MessageDialog(rgcs.Erro.Message);
                    this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        msd.ShowAsync();
                    });
                }
            });
        }
示例#13
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();
                });
            }
        }
示例#14
0
        void ageol_PositionChanged(AGeolocator sender, APositionChangedEventArgs args)
        {
            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
            {
                CurrentLocation = args.LngLat;

                try
                {
                    //update current location
                    if (this.currentViewType != null && this.currentViewType == typeof(MapView))
                    {
                        AMarker marker             = new AMarker();
                        marker.LngLat              = this.CurrentLocation;
                        marker.IconURI             = new Uri("http://api.amap.com/webapi/static/Images/marker_sprite.png ");
                        ATip tip                   = new ATip();
                        tip.Title                  = "当前位置";
                        tip.ContentText            = "Current Position";
                        marker.TipFrameworkElement = tip;
                        this.map.Children.Clear();
                        this.map.Children.Add(marker);
                        marker.OpenTip();
                    }

                    if (DateTime.Now.ToFileTime() - lastUpdate.ToFileTime() < 30000000)
                    {
                        return;
                    }

                    //convert location to sogo location
                    string points = string.Format("{0},{1}", CurrentLocation.LngX, CurrentLocation.LatY);
                    string url    = SogoMapService.GetTranslationInfoURL(points);
                    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, url);

                    HttpResponseMessage response = await httpClient.SendAsync(request,
                                                                              HttpCompletionOption.ResponseHeadersRead);

                    string result = "";
                    using (Stream responseStream = await response.Content.ReadAsStreamAsync())
                    {
                        int read             = 0;
                        byte[] responseBytes = new byte[1000];
                        do
                        {
                            read       = await responseStream.ReadAsync(responseBytes, 0, responseBytes.Length);
                            string tmp = System.Text.Encoding.GetEncoding("GBK").GetString(responseBytes, 0, read);
                            result    += tmp;
                        }while (read != 0);
                    }

                    TranslationLocation translation = SogoMapService.GetTranslationInfo(result);
                    if (translation != null && translation.response.points.Length == 1)
                    {
                        this.CurrentSogoLongitude = translation.response.points[0].longitude;
                        this.CurrentSogoLatitude  = translation.response.points[0].latitude;
                    }
                }
                catch
                {
                }
                //check whether need alert
                this.CheckReminder();
                this.lastUpdate = DateTime.Now;
            });
        }
示例#15
0
        private async void busroute()
        {
            markLayer.Children.Clear();
            BusRouteSearchOption rgo = new BusRouteSearchOption();
            rgo.X1 = marker.LngLat.LngX;
            rgo.Y1 = marker.LngLat.LatY;
            rgo.X2 = marker2.LngLat.LngX;
            rgo.Y2 = marker2.LngLat.LatY;
            rgo.CityCode = "010";
            APolyline pol = new APolyline();
            pol.LineThickness = 5;
            ObservableCollection<ALngLat> lnglatRoute = new ObservableCollection<ALngLat>();  //线路坐标
            lnglatRoute.Add(new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY));
            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, () =>
                {
                    ALngLat lnglat = new ALngLat(marker.LngLat.LngX, marker.LngLat.LatY);
                    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(marker2.LngLat.LngX, marker2.LngLat.LatY);
                    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[] { ',' });
                                try
                                {
                                    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 marker3 = new AMarker();
                                    marker3.Anchor = new Point(0.46, 1);
                                    marker3.IconURI = new Uri("http://api.amap.com/webapi/static/Images/bx11.png");
                                    marker3.LngLat = lnglatpassdeport;
                                    marker3.TipFrameworkElement = tipStart;
                                    markLayer.Children.Add(marker3);
                                    //  Canvas.SetTop(marker,100);
                                    marker3.TipAnchor = new Point(0.35, 1);
                                }
                                catch (Exception e)
                                {
                                    MessageDialog msg = new MessageDialog("无法找到站牌");
                                    msg.ShowAsync();
                                }
                            }
                        }
                        break;
                    }


                    pol.LngLats = lnglatRoute;
                    markLayer.Children.Insert(0, pol);

                    map.SetOverlaysFitView();
                });
            }


        }
        /// <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 BusLineSearchTest(string ids, string cityCode)
        {
            BusLineSearchOption rgo = new BusLineSearchOption();

            rgo.Ids      = ids;
            rgo.CityCode = cityCode;
            BusLineSearchResult rgcs = await BusLineSearch.BusLineSearchWithOption(rgo);

            this.Dispatcher.RunAsync(CoreDispatcherPriority.High, () =>
            {
                IEnumerable <BusLine> bl = rgcs.BusLineList;

                if (rgcs.Erro == null && bl != null)
                {
                    SearchTextGrid.Visibility = Visibility.Collapsed;

                    ObservableCollection <ALngLat> lnglatRoute = new ObservableCollection <ALngLat>(); //线路坐标
                    IEnumerable <String> lnglatstring;
                    foreach (BusLine bs in bl)
                    {
                        IEnumerable <Station> ss = bs.StationList;

                        foreach (Station s in ss)
                        {
                            s.Name = s.StationNum + " " + s.Name;
                        }
                        PoiListView.DataContext = ss;
                        lnglatstring            = bs.XYs.Split(new Char[] { ';' });

                        foreach (String ssss in lnglatstring)
                        {
                            String[] lnglatds = ssss.Split(new Char[] { ',' });
                            lnglatRoute.Add(new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1])));
                        }
                        int i = 0;
                        foreach (Station st in ss)
                        {
                            i++;
                            String[] lnglatds             = st.XY.Split(new Char[] { ',' });
                            ALngLat markerlnglat          = new ALngLat(Double.Parse(lnglatds[0]), Double.Parse(lnglatds[1]));
                            AMarker poiMarker             = new AMarker();
                            poiMarker.Anchor              = new Point(0.5, 0.5);
                            poiMarker.LngLat              = markerlnglat;
                            ATip tip                      = new ATip();
                            tip.Title                     = st.Name;
                            tip.ContentText               = "站点序号: " + st.StationNum;
                            poiMarker.TipFrameworkElement = tip;
                            markerList.Add(poiMarker);
                        }
                        PoiListView.Visibility = Visible;
                        APolyline pol          = new APolyline();
                        pol.LineThickness      = 5;
                        pol.LngLats            = lnglatRoute;
                        markLayer.Children.Add(pol);
                        markLayer.SetOverlaysFitView();
                        try
                        {
                            PoiListView.SelectedIndex = 0;
                        }
                        catch
                        {
                        }
                    }
                }
                else
                {
                    MessageDialog msd = new MessageDialog(rgcs.Erro.Message);
                    this.Dispatcher.RunAsync(CoreDispatcherPriority.Low, () =>
                    {
                        msd.ShowAsync();
                    });
                    Debug.WriteLine(rgcs.Erro.Message);
                }
            });
        }
示例#18
0
        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();
                });
            }
        }