예제 #1
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);
            }
        }
예제 #2
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);
            }
        }
예제 #3
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;
            }
        }
예제 #4
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);
            }
        }