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); } }
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); } }
private void ToGuangzhouRegion(object sender, RoutedEventArgs e) { const double interval = 1; var guangzhouRegion = new LngLatBoundingBox(new LngLat(guangzhou.Longitude - interval, guangzhou.Latitude - interval), new LngLat(guangzhou.Longitude + interval, guangzhou.Latitude + interval)); aMapControl.TrySetViewBoundsAsync(guangzhouRegion, AMapAnimationKind.Default); }
private void GroundOverlay_OnClick(object sender, RoutedEventArgs e) { aMapControl.TrySetViewBoundsAsync( new LngLatBoundingBox(new LngLat(116.384377, 39.935029), new LngLat(116.388331, 39.939577)), AMapAnimationKind.Default); aMapGroundOverlay = new AMapGroundOverlay { Bound = new LngLatBoundingBox(new LngLat(116.384377, 39.935029), new LngLat(116.388331, 39.939577)), Image = RandomAccessStreamReference.CreateFromUri(new Uri( "ms-appx:///Assets/2.png", UriKind.RelativeOrAbsolute)) }; baseLayer.Add(aMapGroundOverlay); }
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; } }