示例#1
0
        void DibujarRuta()
        {
            try
            {
                var options = new PolylineOptions();

                var colorInt = Colores.Accent;

                options.InvokeColor(colorInt);
                options.InvokeWidth(5);
                options.Visible(true);

                foreach (var posicion in _posiciones.OrderBy(p => p.Fecha))
                {
                    var coordenada = posicion.Coordenada;

                    options.Add(new LatLng(coordenada.Latitud, coordenada.Longitud));
                }

                _mapa.AddPolyline(options);
            }
            catch (Exception ex)
            {
                AlertMessage.Show(Activity, $"Ha ocurrido un error: {ex.Message}", ToastLength.Long);
            }
        }
示例#2
0
        private void PolylineDemo(HuaweiMap hMap)
        {
            hMap.Clear();

            Polyline        polyline1;
            PolylineOptions polyline1Options = new PolylineOptions()
                                               .Add(new LatLng(41.01929, 28.967267), new LatLng(41.016785, 28.986971), new LatLng(41.001917, 28.978743), new LatLng(41.002298, 28.954132));

            polyline1Options.InvokeColor(Color.Blue);
            polyline1Options.InvokeWidth(20);
            // polyline1Options.InvokeZIndex(2);
            polyline1Options.Visible(false);
            polyline1Options.Clickable(true);
            polyline1 = hMap.AddPolyline(polyline1Options);


            Polyline        polyline2;
            PolylineOptions polyline2Options = new PolylineOptions()
                                               .Add(new LatLng(41.010410, 28.978511), new LatLng(41.035243, 29.026812), new LatLng(41.022122, 29.00653), new LatLng(41.00415, 29.012449), new LatLng(41.001699, 28.978743));

            polyline2Options.InvokeColor(Color.Red);
            polyline1Options.InvokeZIndex(1);
            polyline2Options.Clickable(true);
            polyline2 = hMap.AddPolyline(polyline2Options);
        }
示例#3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            startLatlng = new LatLng(Intent.GetDoubleExtra("StartLatitude", 0), Intent.GetDoubleExtra("StartLongitude", 0));
            isLine      = Intent.GetBooleanExtra("isLine", false);
            if (isLine)
            {
                endLatlng = new LatLng(Intent.GetDoubleExtra("EndLatitude", 0), Intent.GetDoubleExtra("EndLongitude", 0));
            }
            SetContentView(Resource.Layout.amap_layout);
            //SetSupportActionBar(new Android.Support.V7.Widget.Toolbar(this));
            var actionBar = SupportActionBar;

            if (actionBar != null)
            {
                actionBar.SetHomeButtonEnabled(true);
                actionBar.SetDisplayHomeAsUpEnabled(true);
            }

            mapView = FindViewById <MapView>(Resource.Id.map);

            //AMapOptions options = new AMapOptions();
            //options.InvokeCamera(new CameraPosition(latlng, 15,  0, 0));
            //mapView = new MapView(this, options);
            mapView.OnCreate(savedInstanceState);

            if (aMap == null)
            {
                aMap = mapView.Map;
                //设置marker
                markerOption = new MarkerOptions().InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueRed))
                               .InvokeTitle("施封位置").InvokeSnippet(Intent.GetStringExtra("startAddress")).InvokePosition(startLatlng).Draggable(true);
                aMap.AddMarker(markerOption).ShowInfoWindow();
                if (isLine)
                {
                    //设置中心点
                    var update = CameraUpdateFactory.NewCameraPosition(new CameraPosition(endLatlng, 5, 0, 0));
                    aMap.MoveCamera(update);
                    //设置marker
                    MarkerOptions endMarkerOption = new MarkerOptions().InvokeIcon(BitmapDescriptorFactory.DefaultMarker(BitmapDescriptorFactory.HueGreen))
                                                    .InvokeTitle("拆封位置").InvokeSnippet(Intent.GetStringExtra("endAddress")).InvokePosition(endLatlng).Draggable(true);
                    aMap.AddMarker(endMarkerOption).ShowInfoWindow();
                    PolylineOptions polylineOptions = new PolylineOptions();
                    var             laglngs         = new ArrayList();
                    laglngs.Add(startLatlng);
                    laglngs.Add(endLatlng);
                    polylineOptions.AddAll(laglngs);
                    polylineOptions.InvokeWidth(10);
                    polylineOptions.InvokeColor(Color.Argb(255, 0, 205, 205));
                    polylineOptions.Visible(true);
                    var polyline = aMap.AddPolyline(polylineOptions);
                    polyline.Visible = true;
                    var endupdate = CameraUpdateFactory.NewCameraPosition(new CameraPosition(endLatlng, 10, 0, 0));
                    aMap.MoveCamera(update);
                }
                else
                {
                    //设置中心点
                    var update = CameraUpdateFactory.NewCameraPosition(new CameraPosition(startLatlng, 15, 0, 0));
                    aMap.MoveCamera(update);
                }
            }
        }