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); } }
private void Button_DrawPolyline_Click(object sender, RoutedEventArgs e) { List <LatLng> lnglats = new List <LatLng>(); lnglats.Add(new LatLng(amap.Center.latitude - 0.02, amap.Center.longitude - 0.02)); lnglats.Add(new LatLng(amap.Center.latitude + 0.03, amap.Center.longitude - 0.02)); polyline = amap.AddPolyline(new AMapPolylineOptions() { Points = lnglats, Color = Color.FromArgb(255, 0, 0, 255), Width = 4, }); this.btnVisible.IsEnabled = true; }
private void Button_DrawLine_Click(object sender, RoutedEventArgs e) { //绘线 List <LatLng> lnglats = new List <LatLng>(); lnglats.Add(new LatLng(amap.Center.latitude + 0.02, amap.Center.longitude + 0.03)); lnglats.Add(amap.Center); lnglats.Add(new LatLng(amap.Center.latitude + 0.05, amap.Center.longitude - 0.06)); polyline = amap.AddPolyline(new AMapPolylineOptions() { Points = lnglats, Color = Color.FromArgb(255, 255, 0, 0), Width = 4 }); }
/// <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) { AMapPolyline line = new AMapPolyline(); pointsOfLine = new[] { new LngLat(116.48236, 39.987326), new LngLat(116.450712, 39.93041) }; line.Path = new AGeopath(pointsOfLine); line.StrokeColor = Colors.Red; baseLayer.Add(line); AMapPolygon rectRectangle = new AMapPolygon(); pointsOfRect = new[] { new LngLat(116.438764, 39.96041), new LngLat(116.438764, 39.963728), new LngLat(116.453712, 39.963728), new LngLat(116.453712, 39.96041) }; rectRectangle.Path = new AGeopath(pointsOfRect); baseLayer.Add(rectRectangle); }
void amap_Loaded(object sender, RoutedEventArgs e) { this.Dispatcher.BeginInvoke(() => { amap.MoveCamera(CameraUpdateFactory.NewLatLngZoom(amap.Center, 12)); List <LatLng> lnglats = new List <LatLng>(); lnglats.Add(new LatLng(amap.Center.latitude + 0.03, amap.Center.longitude + 0.04)); lnglats.Add(new LatLng(amap.Center.latitude - 0.03, amap.Center.longitude - 0.04)); //绘圆 circle = mapLayer.AddCircle(new AMapCircleOptions() { Center = amap.Center, Radius = 2000, FillColor = Color.FromArgb(80, 0, 0, 255), ZIndex = 5, }); //绘线 polyline = mapLayer.AddPolyline(new AMapPolylineOptions() { Points = lnglats, Width = 5, Color = Color.FromArgb(255, 255, 0, 0), ZIndex = 8, }); marker1 = mapLayer.AddMarker(new AMapMarkerOptions() { Position = amap.Center, Title = "Title", Snippet = "Snippet", IconUri = new Uri("Images/AZURE.png", UriKind.Relative), }); marker2 = mapLayer.AddMarker(new AMapMarkerOptions() { Position = amap.Center, Title = "Title", Snippet = "Snippet", IconUri = new Uri("Images/RED.png", UriKind.Relative), Anchor = new Point(1, 1), }); }); }
private void Polyline_Click(object sender, RoutedEventArgs e) { var lngLat1 = new LngLat(aMapControl.Center.Longitude - 0.06, aMapControl.Center.Longitude + 0.06); var lngLat2 = aMapControl.Center; var lngLat3 = new LngLat(aMapControl.Center.Longitude + 0.06, aMapControl.Center.Latitude + 0.06); var list = new List <LngLat> { lngLat1, lngLat2, lngLat3 }; polyline = new AMapPolyline { Path = new AGeopath(list), StrokeColor = Colors.Red, Cap = Cap.BUTT, Joint = Joint.MITER, StrokeThickness = 10 }; baseLayer.Add(polyline); }
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); } }
private async void Car_OnClick(object sender, RoutedEventArgs e) { baseLayer.Clear(); //116.481028, 39.989643, 116.465302, 40.004717 AMapRouteResults rts = await AMapNavigationSearch.DrivingNavigation(start.Longitude, start.Latitude, end.Longitude, end.Latitude); #region 线段是一段段给的 //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) // { // Debug.WriteLine(st.Instruction); // var icon = new AMapIcon // { // Location = LngLatsFromString(st.Polyline).FirstOrDefault(), // Image = RandomAccessStreamReference.CreateFromUri(new Uri("ms-appx:///Assets/car.png", // UriKind.RelativeOrAbsolute)) // }; // IEnumerable<LngLat> lnglats = LngLatsFromString(st.Polyline); // var polyline = new AMapPolyline {Path = new AGeopath(lnglats)}; // await baseLayer.Add(polyline); // await baseLayer.Add(icon); // } // } //} //else //{ // Debug.WriteLine(rts.Erro.Message); //} #endregion if (rts.Erro == null) { if (rts.Count == 0) { Debug.WriteLine("无查询结果"); return; } AMapRoute route = rts.Route; List <LngLat> alLngLats = new List <LngLat>(); 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) { IEnumerable <LngLat> lnglats = LngLatsFromString(st.Polyline); alLngLats.AddRange(lnglats); } } AMapPolyline polyline = new AMapPolyline(); polyline.Path = new AGeopath(alLngLats); await baseLayer.Add(polyline); } else { Debug.WriteLine(rts.Erro.Message); } }
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); } }
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); } }