Ejemplo n.º 1
0
        private async void AddLayerContainIcons(object sender, RoutedEventArgs e)
        {
            var layer = new AMapLayer();


            RandomAccessStreamReference rsa =
                RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png",
                                                                  UriKind.RelativeOrAbsolute));

            for (int i = 0; i < 1000; i++)
            {
                var icon = new AMapIcon
                {
                    //Image =
                    //    RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png",
                    //        UriKind.RelativeOrAbsolute)),

                    Image    = rsa,
                    Location = new LngLat(116.394653 + i * 0.01, 39.911843 + i * 0.01),
                };

                await layer.Add(icon);
            }
            aMapControl.Layers.Add(layer);
        }
        private async void Walk_OnClick(object sender, RoutedEventArgs e)
        {
            baseLayer.Clear();

            var man =
                RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/man.png",
                                                                  UriKind.RelativeOrAbsolute));

            AMapRouteResults rts =
                await
                AMapNavigationSearch.WalkingNavigation(start.Longitude, start.Latitude, end.Longitude, end.Latitude,
                                                       0);

            if (rts.Erro == null)
            {
                if (rts.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                AMapRoute       route = rts.Route;
                List <AMapPath> paths = route.Paths.ToList();

                foreach (AMapPath item in paths)
                {
                    Debug.WriteLine("起点终点距离:" + item.Distance);
                    Debug.WriteLine("预计耗时:" + item.Duration / 60 + "分钟");
                    Debug.WriteLine("导航策略:" + item.Strategy);

                    //画路线
                    List <AMapStep> steps = item.Steps.ToList();
                    foreach (AMapStep st in steps)
                    {
                        var icon = new AMapIcon
                        {
                            Location = LngLatsFromString(st.Polyline).FirstOrDefault(),
                            Image    = man
                        };


                        Debug.WriteLine(st.Instruction);

                        var polyline = new AMapPolyline {
                            Path = new AGeopath(LngLatsFromString(st.Polyline))
                        };

                        await baseLayer.Add(icon);

                        await baseLayer.Add(polyline);
                    }
                }
            }
            else
            {
                Debug.WriteLine(rts.Erro.Message);
            }
        }
Ejemplo n.º 3
0
        private async void KeywordSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baselayer.Clear();
            aMapControl.HideInfoWindow();

            bool groupbuy = false;
            bool discount = false;

            string keywords = "肯德基";

            string types = "快餐厅";

            string city = "北京";

            AMapFilterOption aMapFilterOption = new AMapFilterOption {
                Groupbuy = groupbuy, Discount = discount
            };

            AMapPOIResults results = await AMapPOISearch.POIKeyWords(keywords, types, aMapFilterOption, 0, 20, 1, Extensions.All, city);

            if (results.Erro == null)
            {
                if (results.POIList == null || results.POIList.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                IEnumerable <AMapPOI> pois    = results.POIList;
                List <LngLat>         lngLats = new List <LngLat>();
                foreach (AMapPOI item in pois)
                {
                    lngLats.Add(new LngLat(item.Location.Lon, item.Location.Lat));

                    var icon = new AMapIcon {
                        Location = new LngLat(item.Location.Lon, item.Location.Lat)
                    };

                    icon.Tapped += icon_Tapped;

                    icon.Data = item.Address;

                    await baselayer.Add(icon);
                }

                LngLatBoundingBoxBuilder builder = new LngLatBoundingBoxBuilder(lngLats);

                aMapControl.TrySetViewBoundsAsync(builder.Build(), AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(results.Erro.Message);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 注意:要开启定位权限
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void LocateClick(object sender, RoutedEventArgs e)
        {
            var    aMapGeolocator = new AMapGeolocator();
            LngLat myLngLat       = await aMapGeolocator.GetLngLatAsync();

            var icon = new AMapIcon {
                Location = myLngLat
            };

            baseLayer.Add(icon);
            await aMapControl.TrySetViewAsync(myLngLat, 15, 0, 0, AMapAnimationKind.Default);
        }
Ejemplo n.º 5
0
        private async void TrackLocationClick(object sender, RoutedEventArgs e)
        {
            MessageDialog messageDialog = new MessageDialog("启动tracking");
            await messageDialog.ShowAsync();

            trackingGeolocator = new AMapGeolocator();
            trackingGeolocator.PositionChanged += aMapGeolocator_PositionChanged;

            //模拟器不能获取经纬度
            var currentLocation = await trackingGeolocator.GetLngLatAsync();

            if (trackingIcon == null)
            {
                trackingIcon = new AMapIcon
                {
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/marker_gps_no_sharing.png",
                                                                          UriKind.RelativeOrAbsolute)),
                    Location = currentLocation,
                    NormalizedAnchorPoint = new Point(0.5, 0.5)
                };
            }

            if (amapcircle == null)
            {
                amapcircle = new AMapCircle
                {
                    FillColor       = Color.FromArgb(80, 100, 150, 255),
                    StrokeThickness = 2,
                    StrokeColor     = Color.FromArgb(80, 0, 0, 255),
                    Center          = currentLocation,
                    Radius          = 500
                };
            }

            bool circleContained       = baseLayer.OverLays.Contains(amapcircle);
            bool trackingIconContained = baseLayer.OverLays.Contains(trackingIcon);

            if (!trackingIconContained)
            {
                baseLayer.Add(trackingIcon);
            }


            if (!circleContained)
            {
                baseLayer.Add(amapcircle);
            }


            aMapControl.TrySetViewAsync(currentLocation, 15, null, null, AMapAnimationKind.Default);
            trackingGeolocator.Start();
        }
Ejemplo n.º 6
0
        private async void BusStopSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baseLayer.Clear();
            var bus = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus.png",
                                                                        UriKind.RelativeOrAbsolute));

            string keywords = "北里";
            uint   offset   = 20;
            uint   page     = 1;
            string city     = "北京";


            AMapBusStopResults busStoprs = await AMapBusSearch.BusStopKeyWords(keywords, offset, page, city);

            if (busStoprs.Erro == null)
            {
                if (busStoprs.BusStopList.Count == 0 || busStoprs.BusStopList == null)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                var           busStops = busStoprs.BusStopList;
                List <LngLat> latLngs  = new List <LngLat>();

                foreach (AMapBusStop bs in busStops)
                {
                    Debug.WriteLine(bs.Id);
                    Debug.WriteLine(bs.Name);
                    Debug.WriteLine(bs.Location.Lat);
                    Debug.WriteLine(bs.Location.Lon);

                    latLngs.Add(new LngLat(bs.Location.Lon, bs.Location.Lat));
                }

                //绘制公交站
                foreach (LngLat latlng in latLngs)
                {
                    var icon = new AMapIcon {
                        Location = latlng, Image = bus
                    };
                    await baseLayer.Add(icon);
                }
                LngLatBoundingBoxBuilder builder = new LngLatBoundingBoxBuilder(latLngs);

                aMapControl.TrySetViewBoundsAsync(builder.Build(), AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(busStoprs.Erro.Message);
            }
        }
Ejemplo n.º 7
0
        private async void NearbySearch_OnClick(object sender, RoutedEventArgs e)
        {
            baselayer.Clear();
            aMapControl.HideInfoWindow();


            LngLat currentLocation = await(new AMapGeolocator()).GetLngLatAsync();


            double centerX = currentLocation.Longitude;
            double centerY = currentLocation.Latitude;

            string keywords = "肯德基";

            string types = "快餐厅";

            uint radius = 500;

            string city = "北京";


            AMapPOIResults result = await AMapPOISearch.POIAround(centerX, centerY, keywords, types, null, radius, 0, 20, 1, Extensions.All, city);

            if (result.Erro == null)
            {
                if (result.POIList == null || result.POIList.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }
                IEnumerable <AMapPOI> pois = result.POIList;

                foreach (AMapPOI item in pois)
                {
                    var icon = new AMapIcon {
                        Location = new LngLat(item.Location.Lon, item.Location.Lat)
                    };

                    icon.Tapped += icon_Tapped;

                    icon.Data = item.Address;

                    await baselayer.Add(icon);
                }

                aMapControl.TrySetViewAsync(currentLocation, 13, 0, 0, AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(result.Erro.Message);
            }
        }
        private void MapIcon_Click(object sender, RoutedEventArgs e)
        {
            aMapIcon = new AMapIcon
            {
                Image =
                    RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                  "ms-appx:///Assets/AZURE.png", UriKind.RelativeOrAbsolute)),
                Location = aMapControl.Center,
                NormalizedAnchorPoint = new Point(0.5, 1),
            };

            baseLayer.Add(aMapIcon);
        }
        /// <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.
        /// This parameter is typically used to configure the page.</param>
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            var    layer1   = new AMapLayer();
            var    layer2   = new AMapLayer();
            var    layer3   = new AMapLayer();
            double interval = 0.1;

            var icon1 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/YELLOW.png", UriKind.RelativeOrAbsolute)),
                Location = aMapControl.Center,
                Data     = "1"
            };

            icon1.Tapped += icon1_Tapped;

            var icon2 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/CYAN.png", UriKind.RelativeOrAbsolute)),
                Location = new LngLat(icon1.Location.Longitude + interval, icon1.Location.Latitude + interval),
                Data     = "2"
            };

            icon2.Tapped += icon2_Tapped;

            var icon3 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/GREEN.png", UriKind.RelativeOrAbsolute)),
                Location = new LngLat(icon2.Location.Longitude + interval, icon2.Location.Latitude + interval),
                Data     = "3"
            };

            icon3.Tapped += icon3_Tapped;

            layer1.Add(icon1);
            layer2.Add(icon2);
            layer3.Add(icon3);


            aMapControl.Layers.Add(layer1);
            aMapControl.Layers.Add(layer2);
            aMapControl.Layers.Add(layer3);


            aMapControl.MapHolding += aMapControl_Holding;
        }
        public LayerManagement()
        {
            this.InitializeComponent();
            ContentGrid.Children.Add(aMapControl);
            aMapControl.Layers.Add(baseLayer);
            aMapControl.ZoomLevel = 9;

            var icon = new AMapIcon
            {
                Location = aMapControl.Center,
                Data     = "1"
            };

            baseLayer.Add(icon);
        }
Ejemplo n.º 11
0
        public MapEvent()
        {
            this.InitializeComponent();
            ContentGrid.Children.Add(aMapControl);
            aMapControl.MapTapped       += aMapControl_MapTapped;
            aMapControl.MapDoubleTapped += aMapControl_MapDoubleTapped;
            aMapControl.MapHolding      += aMapControl_MapHolding;

            var icon = new AMapIcon();

            icon.Location = aMapControl.Center;

            aMapControl.Layers.Add(baselayer);
            baselayer.Add(icon);
        }
Ejemplo n.º 12
0
        void icon_Tapped(object sender, AMapIcon e)
        {
            TextBlock textBlock = new TextBlock();

            textBlock.Text       = e.Data.ToString();
            textBlock.FontSize   = 20;
            textBlock.Foreground = new SolidColorBrush(Colors.Black);

            Grid info = new Grid();

            info.Width      = 100;
            info.Height     = 100;
            info.Background = new SolidColorBrush(Colors.White);
            info.Children.Add(textBlock);

            e.ShowInfoWindow(info);
        }
        /// <summary>
        ///     在不同的层上加入不同的marker
        /// 来测试层的功能是否实现
        /// </summary>
        private async void AddMarkersAtDifferentLayer()
        {
            var    layer1   = new AMapLayer();
            var    layer2   = new AMapLayer();
            var    layer3   = new AMapLayer();
            double interval = 0.1;

            var icon1 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/YELLOW.png", UriKind.RelativeOrAbsolute)),
                Location = aMapControl.Center,
                Data     = "1"
            };


            var icon2 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/CYAN.png", UriKind.RelativeOrAbsolute)),
                Location = new LngLat(icon1.Location.Longitude + interval, icon1.Location.Latitude + interval),
                Data     = "2"
            };


            var icon3 = new AMapIcon
            {
                Image = RandomAccessStreamReference.CreateFromUri(new Uri(
                                                                      "ms-appx:///Assets/GREEN.png", UriKind.RelativeOrAbsolute)),
                Location = new LngLat(icon2.Location.Longitude + interval, icon2.Location.Latitude + interval),
                Data     = "3"
            };

            layer1.Add(icon1);
            layer2.Add(icon2);
            layer3.Add(icon3);


            aMapControl.Layers.Add(layer1);
            aMapControl.Layers.Add(layer2);
            aMapControl.Layers.Add(layer3);
        }
Ejemplo n.º 14
0
        private async void IdSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baselayer.Clear();
            aMapControl.HideInfoWindow();

            string id = "B000A07060";


            AMapPOIResults results = await AMapPOISearch.POIID(id);

            if (results.Erro == null)
            {
                if (results.POIList == null || results.POIList.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                foreach (AMapPOI item in results.POIList)
                {
                    var icon = new AMapIcon {
                        Location = new LngLat(item.Location.Lon, item.Location.Lat)
                    };

                    icon.Tapped += icon_Tapped;

                    icon.Data = item.Address;

                    await baselayer.Add(icon);
                }

                aMapControl.TrySetViewAsync(
                    new LngLat(results.POIList[0].Location.Lon, results.POIList[0].Location.Lat), null, null, null,
                    AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(results.Erro.Message);
            }
        }
Ejemplo n.º 15
0
        private async void LineIdSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baseLayer.Clear();
            string crashid = " 440100014234";

            string id = "110100013752";


            AMapBusLineResults busLines = await AMapBusSearch.BusLineIDSearch(id);

            if (busLines.Erro == null)
            {
                if (busLines.BusLineList == null || busLines.BusLineList.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                List <AMapBusLine> busLine = busLines.BusLineList.ToList();

                //Id 搜索 只会搜索到一个
                AMapBusLine bl = busLine.FirstOrDefault();

                Debug.WriteLine(bl.Name);
                List <LngLat> latlng = LngLatsFromString(bl.Polyline);

                AMapPolyline polyline = new AMapPolyline
                {
                    Path            = new AGeopath(latlng),
                    StrokeColor     = Colors.Blue,
                    StrokeThickness = 10
                };

                AMapIcon start = new AMapIcon
                {
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_start_pic.png",
                                                                          UriKind.RelativeOrAbsolute)),
                    Location = latlng.FirstOrDefault()
                };

                AMapIcon end = new AMapIcon
                {
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_end_pic.png",
                                                                          UriKind.RelativeOrAbsolute)),
                    Location = latlng.LastOrDefault()
                };

                await baseLayer.Add(start);

                await baseLayer.Add(end);

                //todo 纹理已经录入,但是为什么会crash
                await baseLayer.Add(polyline);
            }
            else
            {
                Debug.WriteLine(busLines.Erro.Message);
            }
        }
Ejemplo n.º 16
0
        private async Task AddressToGeoCode(string address)
        {
            var azure = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/AZURE.png"));


            AMapGeoCodeResults result = await AMapGeoCodeSearch.AddressToGeoCode(address);

            if (result.Erro == null)
            {
                if (result.GeoCodeList == null || !result.GeoCodeList.Any())
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }


                IEnumerable <AMapGeoCode> geocode = result.GeoCodeList;
                int i = 0;
                IList <AMapGeoCode> aMapGeoCodes = geocode as IList <AMapGeoCode> ?? geocode.ToList();
                foreach (AMapGeoCode gcs in aMapGeoCodes)
                {
                    i++;
                    Debug.WriteLine(gcs.Adcode);
                    Debug.WriteLine(gcs.Building);
                    Debug.WriteLine(gcs.City);
                    Debug.WriteLine(gcs.District);
                    Debug.WriteLine(gcs.FormattedAddress);
                    Debug.WriteLine(gcs.Province);

                    //todo township
                    //Debug.WriteLine(gcs.Township);

                    Debug.WriteLine(gcs.Location.Lon);
                    Debug.WriteLine(gcs.Location.Lat);
                    Debug.WriteLine(gcs.LevelList[0]);

                    var icon = new AMapIcon
                    {
                        Location = new LngLat(gcs.Location.Lon, gcs.Location.Lat),
                        Data     = new
                        {
                            A = gcs.FormattedAddress,
                            B = gcs.District
                        },
                        Image = azure
                    };

                    await baseLayer.Add(icon);
                }
                //如果返回的geocode数大于1个,调整视图
                if (aMapGeoCodes.Count() > 1)
                {
                    var builder = new LngLatBoundingBoxBuilder();
                    foreach (IAMapOverLay overlay in baseLayer.OverLays)
                    {
                        if (overlay as AMapIcon != null)
                        {
                            builder.Include((overlay as AMapIcon).Location);
                        }
                    }

                    aMapControl.TrySetViewBoundsAsync(builder.Build(), AMapAnimationKind.Default);
                }
                else
                {
                    aMapControl.TrySetViewAsync(new LngLat(aMapGeoCodes.FirstOrDefault().Location.Lon,
                                                           aMapGeoCodes.FirstOrDefault().Location.Lat), null, null, null, AMapAnimationKind.Default);
                }

                Debug.WriteLine(i);
            }
            else
            {
                addressOutputTextblock.Text = result.Erro.Message;
            }
        }
Ejemplo n.º 17
0
        private async void PolygonSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baselayer.Clear();
            aMapControl.HideInfoWindow();


            string keywords = "肯德基";
            string types    = "快餐厅";
            uint   offset   = 50;
            string city     = "北京";

            var lngLats = new List <LngLat>
            {
                new LngLat(aMapControl.Center.Longitude + 0.03, aMapControl.Center.Latitude + 0.02),
                new LngLat(aMapControl.Center.Longitude - 0.03, aMapControl.Center.Latitude + 0.03),
                new LngLat(aMapControl.Center.Longitude - 0.03, aMapControl.Center.Latitude - 0.026),
                new LngLat(aMapControl.Center.Longitude + 0.035, aMapControl.Center.Latitude - 0.04),
                new LngLat(aMapControl.Center.Longitude + 0.045, aMapControl.Center.Latitude - 0.046)
            };

            var polygon = new AMapPolygon
            {
                FillColor       = Color.FromArgb(30, 255, 0, 255),
                Path            = new AGeopath(lngLats),
                StrokeColor     = Color.FromArgb(255, 102, 136, 255),
                StrokeThickness = 2
            };

            await baselayer.Add(polygon);


            SearchPolygon searchpolygon = new SearchPolygon();

            icons = new List <AMapIcon>();
            //多边形
            searchpolygon.Points = new List <AMapLocation>
            {
                new AMapLocation()
                {
                    Lon = lngLats[0].Longitude, Lat = lngLats[0].Latitude
                },
                new AMapLocation()
                {
                    Lon = lngLats[1].Longitude, Lat = lngLats[1].Latitude
                },
                new AMapLocation()
                {
                    Lon = lngLats[2].Longitude, Lat = lngLats[2].Latitude
                },
                new AMapLocation()
                {
                    Lon = lngLats[3].Longitude, Lat = lngLats[3].Latitude
                },
                new AMapLocation()
                {
                    Lon = lngLats[4].Longitude, Lat = lngLats[4].Latitude
                }
            };

            AMapPOIResults result = await AMapPOISearch.POIPolygon(keywords, types, searchpolygon, null, 0, offset, 1, Extensions.All, city);

            if (result.Erro == null)
            {
                if (result.POIList == null || result.POIList.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }
                IEnumerable <AMapPOI> pois = result.POIList;
                foreach (AMapPOI item in pois)
                {
                    var icon = new AMapIcon {
                        Location = new LngLat(item.Location.Lon, item.Location.Lat)
                    };

                    icon.Tapped += icon_Tapped;

                    icon.Data = item.Address;

                    await baselayer.Add(icon);;
                }

                LngLatBoundingBoxBuilder builder = new LngLatBoundingBoxBuilder(lngLats);


                aMapControl.TrySetViewBoundsAsync(builder.Build(), AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(result.Erro.Message);
            }
        }
 void icon3_Tapped(object sender, AMapIcon e)
 {
     e.ShowInfoWindow(new InfoWindowControl(Colors.Red, e.Data.ToString()), new Point(0.5, 1), 20);
 }
Ejemplo n.º 19
0
        private async void BusLineSearch_OnClick(object sender, RoutedEventArgs e)
        {
            baseLayer.Clear();


            var busRef = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus.png",
                                                                           UriKind.RelativeOrAbsolute));

            string keywords = "404";
            uint   offset   = 20;
            uint   page     = 1;
            string city     = "北京";

            AMapBusLineResults busLines = await AMapBusSearch.BusLineKeyWords(keywords, offset, page, city, Extensions.All);

            if (busLines.Erro == null)
            {
                if (busLines.BusLineList.Count == 0 || busLines.BusLineList == null)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                IEnumerable <AMapBusLine> bLines = busLines.BusLineList;


                AMapIcon start = new AMapIcon
                {
                    Location =
                        new LngLat(bLines.FirstOrDefault().Bus_stops[0].Location.Lon,
                                   bLines.FirstOrDefault().Bus_stops[0].Location.Lat),
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_start_pic.png",
                                                                          UriKind.RelativeOrAbsolute))
                };



                AMapIcon end = new AMapIcon
                {
                    Location =
                        new LngLat(bLines.FirstOrDefault().Bus_stops.Last().Location.Lon,
                                   bLines.FirstOrDefault().Bus_stops.Last().Location.Lat),
                    Image =
                        RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_end_pic.png",
                                                                          UriKind.RelativeOrAbsolute))
                };

                await baseLayer.Add(start);

                await baseLayer.Add(end);

                List <LngLat> lnglats = LngLatsFromString(bLines.FirstOrDefault().Polyline);

                AMapPolyline polyline = new AMapPolyline {
                    Path = new AGeopath(lnglats)
                };

                await baseLayer.Add(polyline);

                List <LngLat> busstops = new List <LngLat>();

                //添加途径公交站
                foreach (AMapBusStop bs in bLines.FirstOrDefault().Bus_stops)
                {
                    busstops.Add(new LngLat(bs.Location.Lon, bs.Location.Lat));
                }

                //去除起始站和终点站
                busstops.RemoveAt(0);
                busstops.RemoveAt(busstops.Count - 1);

                foreach (LngLat lnglat in busstops)
                {
                    var bus = new AMapIcon
                    {
                        Location = lnglat,
                        Image    = busRef
                    };
                    await baseLayer.Add(bus);
                }


                aMapControl.TrySetViewBoundsAsync(new LngLatBoundingBox(lnglats), AMapAnimationKind.Default);
            }
            else
            {
                Debug.WriteLine(busLines.Erro.Message);
            }
        }
 void icon2_Tapped(object sender, AMapIcon e)
 {
     e.ShowInfoWindow(new InfoWindowControl(Colors.Green, e.Data.ToString()), new Point(1, 1), 0);
 }
        private async void Bus_OnClick(object sender, RoutedEventArgs e)
        {
            baseLayer.Clear();

            string           city = "北京";
            AMapRouteResults rts  =
                await
                AMapNavigationSearch.BusNavigation(start.Longitude, start.Latitude, end.Longitude, end.Latitude, 0,
                                                   false, city);

            if (rts.Erro == null)
            {
                if (rts.Count == 0)
                {
                    Debug.WriteLine("无查询结果");
                    return;
                }

                AMapRoute route = rts.Route;

                List <AMapTransit> transits = route.Transits.ToList();
                List <AMapSegment> segments = transits.FirstOrDefault(p => p.Segments != null).Segments.ToList();



                var busEnd = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_end_pic.png",
                                                                               UriKind.RelativeOrAbsolute));

                var busStart = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus_start_pic.png",
                                                                                 UriKind.RelativeOrAbsolute));


                foreach (AMapSegment item in segments)
                {
                    var destination = new AMapIcon
                    {
                        Location = new LngLat(item.Walking.Destination.Lon, item.Walking.Destination.Lat),
                        Image    = busEnd
                    };


                    var origin = new AMapIcon
                    {
                        Location = new LngLat(item.Walking.Origin.Lon, item.Walking.Origin.Lat),
                        Image    = busStart
                    };

                    await baseLayer.Add(origin);

                    await baseLayer.Add(destination);


                    //绘制步行路径
                    foreach (AMapStep sp in item.Walking.Steps)
                    {
                        var polyline = new AMapPolyline
                        {
                            Path        = new AGeopath(LngLatsFromString(sp.Polyline)),
                            StrokeColor = Colors.Blue
                        };

                        await baseLayer.Add(polyline);

                        //Debug.WriteLine(line.Points.Count);
                        //Debug.WriteLine("Walking.Steps:" + sp.Polyline);
                    }
                    //绘制公交路径
                    foreach (AMapBusLine busLine in item.BusLine)
                    {
                        var polyline = new AMapPolyline
                        {
                            Path        = new AGeopath(LngLatsFromString(busLine.Polyline)),
                            StrokeColor = Colors.Green
                        };



                        await baseLayer.Add(polyline);

                        if (busLine.Via_stops == null)
                        {
                            continue;
                        }


                        RandomAccessStreamReference bus =
                            RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/bus.png",
                                                                              UriKind.RelativeOrAbsolute));


                        foreach (AMapBusStop busstop in busLine.Via_stops)
                        {
                            var busIcon = new AMapIcon
                            {
                                Location = new LngLat(busstop.Location.Lon, busstop.Location.Lat),
                                Image    = bus
                            };
                            await baseLayer.Add(busIcon);
                        }
                    }
                }
            }
            else
            {
                Debug.WriteLine(rts.Erro.Message);
            }
        }
 void icon1_Tapped(object sender, AMapIcon e)
 {
     e.ShowInfoWindow(new InfoWindowControl(Colors.Blue, e.Data.ToString()));
 }