protected override void OnMapReady(GoogleMap googleMap)
        {
            googleMap.UiSettings.ZoomControlsEnabled = false;

            ClusterManager          = new ClusterManager(Context, googleMap);
            ClusterManager.Renderer = new ClusterRenderer(Context, googleMap, ClusterManager);

            var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_pin_navigation);

            LocationMarkerOptions.SetIcon(icon);
            LocationMarkerOptions.Anchor(0.5f, 0.5f);
            LocationMarkerOptions.InvokeZIndex(1);

            var mapTile = (MapTile)Element;

            mapTile.PinUpdating      += (sender, args) => Functions.SafeCall(UpdatePins);
            mapTile.LocationUpdating += (sender, args) => Functions.SafeCall(UpdateLocationPinPosition);
            mapTile.HeadingUpdating  += (sender, args) => Functions.SafeCall(UpdateLocationPinHeading);

            googleMap.MapClick          += Map_MapClick;
            googleMap.CameraMoveStarted += Map_CameraMoveStarted;
            googleMap.CameraIdle        += Map_CameraPositionIdle;
            googleMap.MarkerClick       += Map_MarkerClick;

            Element.SizeChanged += (sender, args) => SetSafeAreaPadding();

            var minskPosition = new Position(MapTile.MinskLat, MapTile.MinskLong);
            var minskRegion   = MapSpan.FromCenterAndRadius(minskPosition, Distance.FromKilometers(5));

            mapTile.MoveToRegion(minskRegion);

            SetSafeAreaPadding();
        }
예제 #2
0
        /// <summary>
        /// Adds a marker to the map
        /// </summary>
        /// <param name="pin">The Forms Pin</param>
        private async void AddPin(TKCustomMapPin pin)
        {
            pin.PropertyChanged += OnPinPropertyChanged;

            var markerWithIcon = new MarkerOptions();

            markerWithIcon.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));

            if (!string.IsNullOrWhiteSpace(pin.Title))
            {
                markerWithIcon.SetTitle(pin.Title);
            }
            if (!string.IsNullOrWhiteSpace(pin.Subtitle))
            {
                markerWithIcon.SetSnippet(pin.Subtitle);
            }

            await this.UpdateImage(pin, markerWithIcon);

            markerWithIcon.Draggable(pin.IsDraggable);
            markerWithIcon.Visible(pin.IsVisible);
            if (pin.Image != null)
            {
                markerWithIcon.Anchor((float)pin.Anchor.X, (float)pin.Anchor.Y);
            }

            this._markers.Add(pin, this._googleMap.AddMarker(markerWithIcon));
        }
예제 #3
0
        private void AddPokemonMarker(Pokemon p)
        {
            var mOps = new MarkerOptions();

            mOps.SetPosition(p.Location);

            if (PokesVisible.Count() < 100)
            {
                mOps.SetIcon(BitmapDescriptorFactory.FromBitmap(GetPokemonMarker(p)));
            }
            else
            {
                var img = BitmapDescriptorFactory.FromResource(pokeResourceMap[p.pokemon_id]);
                mOps.SetIcon(img);
            }
            mOps.Anchor(0.5f, 0.5f);
            var marker = map.AddMarker(mOps);

            marker.Tag = $"poke:{p.id}";
            if (marker != null)
            {
                p.PokeMarker = marker;
                PokesVisible.Add(p);
            }
        }
예제 #4
0
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            if (pin is CirclePin)
            {
                //create an overlay circle, and add to map
                var circleOptions = new CircleOptions();
                circleOptions.InvokeCenter(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
                circleOptions.InvokeRadius(PublishedData.PinOverlayRadius);
                circleOptions.InvokeFillColor(0X66FF0000);
                circleOptions.InvokeStrokeColor(0X66FF0000);
                circleOptions.InvokeStrokeWidth(0);
                Circle circle = NativeMap.AddCircle(circleOptions);
                (pin as CirclePin).Overlay = circle;
            }

            // marker,or pin.
            var marker = new MarkerOptions();

            marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            marker.Anchor(0.5f, 0.5f);// set anchor to to middle of icon
            marker.SetTitle(pin.Label);
            marker.SetSnippet(pin.Address);
            Bitmap imageBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.pin);
            Bitmap resizedIcon = Bitmap.CreateScaledBitmap(imageBitmap, 50, 50, false);

            marker.SetIcon(BitmapDescriptorFactory.FromBitmap(resizedIcon));

            return(marker);
        }
예제 #5
0
        private void AddGymMarker(Gym g)
        {
            var mOps = new MarkerOptions();

            mOps.SetPosition(g.Location);
            int img = 0;

            switch (g.team)
            {
            case Team.Mystic:
                img = Resource.Mipmap.mystic;
                break;

            case Team.Valor:
                img = Resource.Mipmap.valor;
                break;

            case Team.Instinct:
                img = Resource.Mipmap.instinct;
                break;

            case Team.None:
                img = Resource.Mipmap.empty;
                break;
            }

            mOps.SetIcon(BitmapDescriptorFactory.FromResource(img));
            mOps.Anchor(0.5f, 0.5f);
            var marker = map.AddMarker(mOps);

            marker.Tag  = $"gym:{g.id}";
            g.GymMarker = marker;
            gymsVisible.Add(g);
        }
예제 #6
0
        public void SetCurrentLocationMarker()
        {
            if (Map != null)
            {
                if (CurrentLocation != null)
                {
                    if (CurrentLocationMarker == null)
                    {
                        MarkerOptions markerOpt = new MarkerOptions()
                                                  .SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_current_location_marker))
                                                  .SetPosition(new LatLng(CurrentLocation.Latitude, CurrentLocation.Longitude));
                        markerOpt.Anchor((float)0.5, (float)0.5);
                        CurrentLocationMarker = Map.AddMarker(markerOpt);

                        CircleOptions circleOpt = new CircleOptions()
                                                  .InvokeRadius(6)
                                                  .InvokeCenter(new LatLng(0, 0))
                                                  .InvokeStrokeColor((new Color(0, 0, 0, 255)).ToArgb())
                                                  .InvokeStrokeWidth((float)0.5)
                                                  .InvokeFillColor((new Color(0, 191, 255, 100).ToArgb()));
                        CurrentLocationAccuracy = Map.AddCircle(circleOpt);
                    }
                    CurrentLocationMarker.Position = new LatLng(CurrentLocation.Latitude, CurrentLocation.Longitude);
                    CurrentLocationAccuracy.Radius = CurrentLocation.Accuracy;
                    CurrentLocationAccuracy.Center = new LatLng(CurrentLocation.Latitude, CurrentLocation.Longitude);
                }
            }
        }
예제 #7
0
        public void DrawArrow(LatLng StartLocation, LatLng EndLocation)
        {
            if (mMarker != null)
            {
                mMarker.Remove();
            }

            matrix = new Matrix();

            if (EndLocation != null && StartLocation != null)
            {
                var Deg = CalcBearing(StartLocation, EndLocation);
                matrix.PostRotate(float.Parse(Deg.ToString()));
                bmRotate = Bitmap.CreateBitmap(bmArrow, 0, 0, bmArrow.Width, bmArrow.Height, matrix, true);

                bmDescriptor = BitmapDescriptorFactory.FromBitmap(bmRotate);

                mkOptions = new MarkerOptions();
                mkOptions.SetIcon(bmDescriptor);
                mkOptions.SetPosition(StartLocation);
                mkOptions.Anchor(0.5f, 0.5f);
                mMarker = map.AddMarker(mkOptions);

                bmRotate.Recycle();
                bmRotate = null;

                ////groundOverlayOptions = new GroundOverlayOptions()
                //groundOverlayOptions = new GroundOverlayOptions()
                //    .Position(StartLocation, bmArrow.Width, bmArrow.Height)
                //    .InvokeImage(bmDescriptor)
                //    .InvokeZIndex(5);
                //myOverlay = map.AddGroundOverlay(groundOverlayOptions);
                //ListArrow.Add(myOverlay);
            }
        }
예제 #8
0
        /// <summary>
        /// initializes the <see cref="MarkerOptions"/>
        /// </summary>
        /// <param name="markerOptions">Instance of the marker options</param>
        /// <param name="setPosition">if <value>true</value>, the position will be updated</param>
        /// <returns><see cref="Task"/></returns>
        public async Task InitializeMarkerOptionsAsync(MarkerOptions markerOptions, bool setPosition = true)
        {
            if (setPosition)
            {
                markerOptions.SetPosition(new LatLng(Pin.Position.Latitude, Pin.Position.Longitude));
            }

            if (!string.IsNullOrWhiteSpace(Pin.Title))
            {
                markerOptions.SetTitle(Pin.Title);
            }
            if (!string.IsNullOrWhiteSpace(Pin.Subtitle))
            {
                markerOptions.SetSnippet(Pin.Subtitle);
            }

            await UpdateImageAsync(markerOptions);

            markerOptions.Draggable(Pin.IsDraggable);
            markerOptions.Visible(Pin.IsVisible);
            markerOptions.SetRotation((float)Pin.Rotation);
            if (Pin.Image != null)
            {
                markerOptions.Anchor((float)Pin.Anchor.X, (float)Pin.Anchor.Y);
            }
        }
        private void AddCircle(LatLng location)
        {
            try
            {
                if (!(circle is null))
                {
                    circle.Remove();
                }

                Drawable drawable = ContextCompat.GetDrawable(this, icMapmarker);

                Bitmap bitmap = Bitmap.CreateBitmap((int)(circleSize * pixelDensity), (int)(circleSize * pixelDensity), Bitmap.Config.Argb8888);
                Canvas canvas = new Canvas(bitmap);
                drawable.SetBounds(0, 0, canvas.Width, canvas.Height);
                drawable.Draw(canvas);

                MarkerOptions markerOptions = new MarkerOptions();
                markerOptions.SetPosition(location);
                markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(bitmap));
                markerOptions.Anchor(0.5f, 0.5f);
                circle = thisMap.AddMarker(markerOptions);
            }
            catch
            {
            }
        }
예제 #10
0
        public static MarkerOptions MakeFinishMarker(Pin poi, int maxWidthImage)
        {
            var marker = new MarkerOptions();

            marker.Anchor(0.5f, 0.5f);
            marker.SetPosition(new LatLng(poi.Position.Latitude, poi.Position.Longitude));
            marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.finish));
            return(marker);
        }
예제 #11
0
        private void addIcon(IconGenerator iconFactory, string text, LatLng position)
        {
            MarkerOptions markerOptions = new MarkerOptions();

            markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(iconFactory.MakeIcon(text)));
            markerOptions.SetPosition(position);
            markerOptions.Anchor(iconFactory.AnchorU, iconFactory.AnchorV);

            getMap().AddMarker(markerOptions);
        }
        /// <summary>
        /// This function customize the native pin based on the custom pin instance/object and then add it to the native map.
        /// </summary>
        /// <param name="pin">Custom pin object instance to add to the map.</param>
        private async void addMarker(CustomPin pin)
        {
            MarkerOptions marker = new MarkerOptions();

            marker.SetTitle(pin.Id);
            marker.SetIcon(BitmapDescriptorFactory.FromBitmap(ResizeImage(pin.ImagePath, ((customMap.PinSizeSource == CustomMap.PinSizeSourceName.Pin) ? (pin.PinSize) : (customMap.PinSize)))));
            marker.SetPosition(new LatLng(pin.Location.Latitude, pin.Location.Longitude));
            marker.Anchor((float)pin.AnchorPoint.X, (float)pin.AnchorPoint.Y);

            MarkerOptionsPinLinkDictionary.Add(nativeMap.AddMarker(marker), pin);
        }
예제 #13
0
        void addIcon(IconGenerator iconFactory, string text, LatLng position)
        {
            return;

            var markerOptions = new MarkerOptions();

            markerOptions.SetIcon(BitmapDescriptorFactory.FromBitmap(iconFactory.MakeIcon(text)));
            markerOptions.SetPosition(position);
            markerOptions.Anchor(iconFactory.AnchorU, iconFactory.AnchorV);

            this.map.AddMarker(markerOptions);
        }
예제 #14
0
        public static MarkerOptions Make(Pin poi, int maxWidthImage, string imageMarkerPath)
        {
            var marker = new MarkerOptions();

            marker.Anchor(0.5f, 0.5f);
            marker.SetPosition(new LatLng(poi.Position.Latitude, poi.Position.Longitude));

            BitmapDescriptor pic = !string.IsNullOrEmpty(imageMarkerPath) ? getBitmap(imageMarkerPath, maxWidthImage) : BitmapDescriptorFactory.FromResource(Resource.Drawable.place_unknown);

            marker.SetIcon(pic);
            return(marker);
        }
예제 #15
0
        private void AddRaidMarker(Raid r)
        {
            var mOps = new MarkerOptions();

            mOps.SetPosition(r.Location);

            mOps.SetIcon(BitmapDescriptorFactory.FromBitmap(GetRaidMarker(r)));
            mOps.Anchor(0.5f, 0.5f);
            var marker = map.AddMarker(mOps);

            marker.Tag   = $"raid:{r.id}";
            r.RaidMarker = marker;
            raidsVisible.Add(r);
        }
예제 #16
0
        private async Task AddPinAsync(IMapPin pin)
        {
            if (_markers.ContainsKey(pin))
            {
                return;
            }

            var mapPin = new MarkerOptions();

            mapPin.InvokeZIndex(pin.ZIndex);

            if (!string.IsNullOrWhiteSpace(pin.Title))
            {
                mapPin.SetTitle(pin.Title);
            }

            if (!string.IsNullOrWhiteSpace(pin.Snippet))
            {
                mapPin.SetSnippet(pin.Snippet);
            }

            mapPin.SetPosition(new LatLng(pin.Location.Latitude, pin.Location.Longitude));

            if (pin.Image != null)
            {
                mapPin.Anchor((float)pin.Anchor.X, (float)pin.Anchor.Y);
            }

            var selected = pin.EqualsSafe(Map.SelectedItem);

            mapPin.SetIcon(await DeterminMarkerImage(pin, selected));

            if (_markers.ContainsKey(pin))
            {
                return;
            }

            var markerView = _googleMap.AddMarker(mapPin);

            _markers.Add(pin, markerView);

            if (selected && Map.CanShowCalloutOnTap)
            {
                markerView.ShowInfoWindow();
            }
            else
            {
                markerView.HideInfoWindow();
            }
        }
        protected override MarkerOptions CreateMarker(Pin pin)
        {
            MarkerOptions options = base.CreateMarker(pin);

            if (pin is SKPin)
            {
                SKPin    sharedMarker = pin as SKPin;
                SKPixmap markerBitmap = DrawMarker(sharedMarker);

                options.SetIcon(BitmapDescriptorFactory.FromBitmap(markerBitmap.ToBitmap()))
                .Visible(sharedMarker.IsVisible);
                options.Anchor((float)sharedMarker.AnchorX, (float)sharedMarker.AnchorY);
            }

            return(options);
        }
        void AddEndMarker(LatLng end)
        {
            Activity?.RunOnUiThread(() =>
            {
                var logicalDensity  = Resources.DisplayMetrics.Density;
                var thicknessPoints = (int)Math.Ceiling(20 * logicalDensity + .5f);
                var b         = ContextCompat.GetDrawable(Activity, Resource.Drawable.ic_end_point) as BitmapDrawable;
                var finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);

                var endMarker = new MarkerOptions();
                endMarker.SetPosition(end);
                endMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
                endMarker.Anchor(.5f, .5f);

                map.AddMarker(endMarker);
            });
        }
예제 #19
0
 void UpdateCar(LatLng latlng)
 {
     if (latlng == null || map == null)
         return;
     Activity?.RunOnUiThread(() =>
     {
         if (carMarker == null)
         {
             var car = new MarkerOptions();
             car.SetPosition(latlng);
             car.Anchor(.5f, .5f);
             carMarker = map.AddMarker(car);
             UpdateCarIcon(viewModel.IsRecording);
             return;
         }
         carMarker.Position = latlng;
     });
 }
예제 #20
0
        private void CreateLabel(Marker marker)
        {
            if (marker.Label.Text == null)
            {
                return;
            }
            Paint labelTextPaint = new Paint();

            labelTextPaint.Flags    = PaintFlags.AntiAlias;
            labelTextPaint.TextSize = marker.Label.TextSize != 0 ? marker.Label.TextSize : 25.0f;
            labelTextPaint.SetStyle(Paint.Style.Stroke);
            labelTextPaint.Color       = Xamarin.Forms.Color.White.ToAndroid();
            labelTextPaint.StrokeWidth = 8.0f;

            Rect boundsText = new Rect();

            labelTextPaint.GetTextBounds(marker.Label.Text, 0, marker.Label.Text.Length, boundsText);
            MarkerOptions options = new MarkerOptions();

            if (marker.ZIndex.HasValue)
            {
                options.InvokeZIndex(marker.ZIndex.Value - 0.1f);
            }
            options.SetPosition(new LatLng(marker.Center.Latitude, marker.Center.Longitude));
            options.Anchor(marker.Label.AnchorPointX, marker.Label.AnchorPointY);
            Bitmap labelBitmap = Bitmap.CreateBitmap(boundsText.Width(), boundsText.Height() * 2, Bitmap.Config.Argb8888);

            Canvas canvas = new Canvas(labelBitmap);

            canvas.DrawText(marker.Label.Text, 0, boundsText.Height() * 2, labelTextPaint);
            labelTextPaint.SetStyle(Paint.Style.Fill);
            labelTextPaint.Color = global::Android.Graphics.Color.DarkGray;
            canvas.DrawText(marker.Label.Text, 0, boundsText.Height() * 2, labelTextPaint);

            options.SetIcon(BitmapDescriptorFactory.FromBitmap(labelBitmap));
            markers.Add(new Marker()
            {
                Id     = marker.Id + "-Label",
                Center = marker.Center
            }, googleMap.AddMarker(options));
        }
예제 #21
0
        private void SetMapData(List <BusInformation> BusesData)
        {
            if (BusesData == null || BusesData.Count == 0)
            {
                return;
            }
            myGoogleMap.Clear();
            busesInformation.Clear();
            busesInformation = BusesData;

            for (int x = 0; x < busesInformation.Count; x++)
            {
                MarkerOptions markerOptions = new MarkerOptions();
                position = new LatLng(Double.Parse(busesInformation[x].Lat), Double.Parse(busesInformation[x].Lon));
                markerOptions.SetPosition(position);
                markerOptions.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_directions_bus));
                markerOptions.Anchor(.5f, .7f);
                markerOptions.SetTitle(x.ToString());
                myGoogleMap.AddMarker(markerOptions);
            }
        }
        /// <summary>
        /// Adds a pin to the current map.
        /// </summary>
        /// <param name="pin">A pin to add.</param>
        private void AddPin(MapExPin pin)
        {
            // If map is not present
            if (this.map == null)
            {
                return;
            }

            // Create a new marker collection
            if (this.markers == null)
            {
                this.markers = new List <Marker>();
            }

            // Setup market options
            var markerOptions = new MarkerOptions();

            markerOptions.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude));
            markerOptions.Anchor(0.5f, 0.5f);
            markerOptions.SetTitle(pin.Label);
            markerOptions.SetSnippet(pin.Address);
            markerOptions.InfoWindowAnchor(0.5f, 0.5f);

            // Setup marker icon
            var icon = MapExRenderer.GetResourceId(pin.Type);

            markerOptions.SetIcon(BitmapDescriptorFactory.FromResource(icon));

            // Add marker to the map
            var marker = this.map.AddMarker(markerOptions);

            this.markers.Add(marker);
            pin.InternalId = marker.Id;

            // Add event handlers
            pin.PropertyChanged += this.OnPinPropertyChanged;
        }
예제 #23
0
        protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            base.OnElementPropertyChanged(sender, e);

            if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
            {
                MapView.Clear();

                foreach (var pin in this.MapControl.ExtendedPins)
                {
                    var marker = new MarkerOptions();
                    marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                    marker.SetTitle(pin.Pin.Label);
                    marker.SetSnippet(pin.Pin.Address);

                    if (MapControl.GetPinViewDelegate != null)
                    {
                        var formsView = MapControl.GetPinViewDelegate(pin);
                        marker = marker.Anchor((float)formsView.AnchorX, (float)formsView.AnchorY);
                        //var nativeView = Utils.ConvertFormsToNative (formsView, new Rectangle (0, 0, (double)Utils.DpToPx ((float)formsView.WidthRequest), (double)Utils.DpToPx ((float)formsView.HeightRequest)));
                        var nativeView = WMapAuxiliarRenderer.LiveMapRenderer.GetNativeView(formsView);
                        Utils.FixImageSourceOfImageViews(nativeView as Android.Views.ViewGroup);

                        var otherView = new FrameLayout(this.Context);
                        nativeView.LayoutParameters = new FrameLayout.LayoutParams(Utils.DpToPx((float)formsView.WidthRequest), Utils.DpToPx((float)formsView.HeightRequest));
                        otherView.AddView(nativeView);

                        var bitmap = Utils.ConvertViewToBitmap(otherView);
                        marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bitmap));
                    }

                    MapView.AddMarker(marker);
                }
                isDrawn = true;
            }
        }
예제 #24
0
        protected override void OnMapReady(GoogleMap googleMap)
        {
            var icon = BitmapDescriptorFactory.FromResource(Resource.Drawable.ic_pin_navigation);

            LocationMarkerOptions.SetIcon(icon);
            LocationMarkerOptions.Anchor(0.5f, 0.5f);
            LocationMarkerOptions.InvokeZIndex(1);

            var mapTile = (MapTile)Element;

            mapTile.PinUpdating      += (sender, args) => Functions.SafeCall(UpdatePins);
            mapTile.LocationUpdating += (sender, args) => Functions.SafeCall(UpdateLocationPinPosition);
            mapTile.HeadingUpdating  += (sender, args) => Functions.SafeCall(UpdateLocationPinHeading);

            NativeMap.MapClick          += Map_MapClick;
            NativeMap.CameraMoveStarted += Map_CameraMoveStarted;
            NativeMap.CameraIdle        += Map_CameraPositionIdle;
            NativeMap.MarkerClick       += Map_MarkerClick;
            NativeMap.UiSettings.ZoomControlsEnabled = false;

            Element.SizeChanged += (sender, args) => SetSafeAreaPadding();

            SetSafeAreaPadding();
        }
예제 #25
0
        protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null || e.OldElement != null)
            {
                return;
            }

            //e.NewElement就是承载的界面,这里就是PCL项目里面的MainPage
            //var mainPage = e.NewElement as TencentMapSamples;
            var mainPage = e.NewElement as Samples.Controls.TencentMap;

            //初始化mapView
            mapView = new MapView(this.Context);
            mapView.OnCreate(null);

            //初始化视图
            layout = new LinearLayout(this.Context);
            layout.AddView(mapView);
            this.AddView(layout);

            //这里可以比对以下我们的写法跟腾讯官网里Java写法的区别,可以看出Java里面的属性是set,get前缀,而在C#里面都被隐藏了,直接用C#惯用的属性写法来代替,而方法则还是同样的SetXXX(),GetXXX(),但是Java是camelCasing,C#用PascalCasing写法(博主非常喜欢C#写法,而很讨厌Java的写法 :-))。这些区别,都是Xamarin 里 绑定Java库的转换规则。

            #region TencentMap类
            //腾讯地图的设置是通过TencentMap类进行设置,可以控制地图的底图类型、显示范围、缩放级别、添加 / 删除marker和图形,此外对于地图的各种回调监听也是绑定到TencentMap。下面是TencentMap类的使用示例:

            //获取TencentMap实例
            TencentMap tencentMap = mapView.Map;
            //设置实时路况开启
            tencentMap.TrafficEnabled = true;
            //设置地图中心点
            tencentMap.SetCenter(new Com.Tencent.Mapsdk.Raster.Model.LatLng(30.605870, 104.068610));
            //设置缩放级别
            tencentMap.SetZoom(11);
            #endregion

            #region UiSettings类
            //UiSettings类用于设置地图的视图状态,如Logo位置设置、比例尺位置设置、地图手势开关等。下面是UiSettings类的使用示例:

            //获取UiSettings实例
            UiSettings uiSettings = mapView.UiSettings;
            //设置logo到屏幕底部中心
            uiSettings.SetLogoPosition(UiSettings.LogoPositionCenterBottom);
            //设置比例尺到屏幕右下角
            uiSettings.SetScaleViewPosition(UiSettings.ScaleviewPositionRightBottom);
            //启用缩放手势(更多的手势控制请参考开发手册)
            uiSettings.SetZoomGesturesEnabled(true);
            #endregion

            #region 使用marker
            //注意,这里要往resources/drawable/里添加一个red_location.png的图片
            var bitmap           = Resources.GetBitmap("red_location.png");
            BitmapDescriptor des = new BitmapDescriptor(bitmap);
            foreach (var item in mainPage.Options)
            {
                MarkerOptions options = new MarkerOptions();

                options.InvokeIcon(des);
                options.InvokeTitle(item.Title);
                options.Anchor(0.5f, 0.5f);
                options.InvokePosition(new LatLng(item.Lat, item.Lng));
                options.Draggable(true);
                Marker marker = mapView.AddMarker(options);
                marker.ShowInfoWindow();
            }

            #endregion
        }
예제 #26
0
 protected BaseIcon()
 {
     MarkerOptions = new MarkerOptions();
     MarkerOptions.Draggable(false);
     MarkerOptions.Anchor(0.5f, 0.5f);
 }
예제 #27
0
        /*
         *      private void SetMapLocation()
         *      {
         *          if (GMap == null) return;
         *
         *          var location = Map.Tag as LatLng;
         *          if (location == null && _userLocation == null) return;
         *
         *          // Calculate the map position and zoom/size
         *          CameraUpdate cameraUpdate = null;
         *          if (_userLocation == null)
         *              cameraUpdate = CameraUpdateFactory.NewLatLngZoom(location, Constants.DefaultResponseMapZoom);
         *          else if (location == null)
         *              cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_userLocation, Constants.DefaultResponseMapZoom);
         *          else
         *          {
         *              var latDelta = Math.Abs(location.Latitude - _userLocation.Latitude);
         *              var longDelta = Math.Abs(location.Longitude - _userLocation.Longitude);
         *              var minLat = Math.Min(location.Latitude, _userLocation.Latitude) - latDelta / 4;
         *              var maxLat = Math.Max(location.Latitude, _userLocation.Latitude) + latDelta / 4;
         *              var minLong = Math.Min(location.Longitude, _userLocation.Longitude) - longDelta / 4;
         *              var maxLong = Math.Max(location.Longitude, _userLocation.Longitude) + longDelta / 4;
         *
         *              LatLngBounds.Builder builder = new LatLngBounds.Builder();
         *              builder.Include(new LatLng(minLat, minLong));
         *              builder.Include(new LatLng(maxLat, maxLong));
         *              // shouldn't need to include these but we'll include them just in case
         *              builder.Include(new LatLng(location.Latitude, location.Longitude));
         *              builder.Include(new LatLng(_userLocation.Latitude, _userLocation.Longitude));
         *              LatLngBounds bounds = builder.Build();
         *              cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 0);
         *          }
         *
         *          // Set the map position
         *          GMap.MoveCamera(cameraUpdate);
         *
         *          // Add a markers
         *          if (location != null)
         *          {
         *              var markerOptions = new MarkerOptions();
         *              markerOptions.SetPosition(location);
         *              if (_colorHue > -1)
         *              {
         *                  var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(_colorHue);
         *                  markerOptions.SetIcon(bmDescriptor);
         *              }
         *              GMap.AddMarker(markerOptions);
         *          }
         *          if (_userLocation != null)
         *          {
         *              var markerOptions0 = new MarkerOptions();
         *              markerOptions0.SetPosition(_userLocation);
         *              markerOptions0.SetIcon(UserLocationIcon);
         *              markerOptions0.Anchor(0.5f, 0.5f);
         *              GMap.AddMarker(markerOptions0);
         *          }
         *
         *          // Set the map type back to normal.
         *          GMap.MapType = GoogleMap.MapTypeNormal;
         *      }
         */



        private async Task DrawMapAsync(bool moveMap = true)
        {
            if (GMap == null)
            {
                return;
            }

            if (_eventLocation == null && _currentUserLocation == null)
            {
                return;
            }

            // Set callback to detect when map has finished loading
            //          _activity.RunOnUiThread(() => { GMap.SetOnMapLoadedCallback(new MapLoadedCallback(Map.Id)); });

            await Task.Run(() =>
            {
                // Calculate the map position and zoom/size
                CameraUpdate cameraUpdate = null;
                if (moveMap)
                {
                    if (_currentUserLocation == null)
                    {
                        // Only event location available
                        cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_eventLocation, Constants.DefaultResponseMapZoom);
                    }
                    else if (_eventLocation == null)
                    {
                        // Only user location available
                        cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_currentUserLocation, Constants.DefaultResponseMapZoom);
                    }
                    else
                    {
                        // Both locations available
                        // get deltas between those locations
                        var latDelta  = Math.Abs(_eventLocation.Latitude - _currentUserLocation.Latitude);
                        var longDelta = Math.Abs(_eventLocation.Longitude - _currentUserLocation.Longitude);
                        // get the boundaries of the map
                        var minLat  = Math.Min(_eventLocation.Latitude, _currentUserLocation.Latitude) - latDelta / 4;
                        var maxLat  = Math.Max(_eventLocation.Latitude, _currentUserLocation.Latitude) + latDelta / 4;
                        var minLong = Math.Min(_eventLocation.Longitude, _currentUserLocation.Longitude) - longDelta / 4;
                        var maxLong = Math.Max(_eventLocation.Longitude, _currentUserLocation.Longitude) + longDelta / 4;

                        LatLngBounds.Builder builder = new LatLngBounds.Builder();
                        builder.Include(new LatLng(minLat, minLong));
                        builder.Include(new LatLng(maxLat, maxLong));
                        // shouldn't need to include these but we'll include them just in case
                        LatLngBounds bounds = builder.Build();
                        cameraUpdate        = CameraUpdateFactory.NewLatLngBounds(bounds, 0);
                    }
                    // Set the map position
                    _activity.RunOnUiThread(() => { GMap.MoveCamera(cameraUpdate); });
                }

                _activity.RunOnUiThread(() => {
                    // Add a markers
                    if (_eventLocation != null)
                    {
                        if (EventLocationMarker == null)
                        {
                            var markerOptions = new MarkerOptions();
                            markerOptions.SetPosition(_eventLocation);
                            if (_colorHue > -1)
                            {
                                var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(_colorHue);
                                markerOptions.SetIcon(bmDescriptor);
                            }
                            EventLocationMarker = GMap.AddMarker(markerOptions);
                        }
                        else
                        {
                            var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(_colorHue);
                            EventLocationMarker.SetIcon(bmDescriptor);
                            EventLocationMarker.Position = _eventLocation;
                        }
                    }
                    if (_currentUserLocation != null)
                    {
                        if (UserLocationMarker == null)
                        {
                            var markerOptions0 = new MarkerOptions();
                            markerOptions0.SetPosition(_currentUserLocation);
                            markerOptions0.SetIcon(UserLocationIcon);
                            markerOptions0.Anchor(0.5f, 0.5f);
                            UserLocationMarker = GMap.AddMarker(markerOptions0);
                        }
                        else
                        {
                            UserLocationMarker.Position = _currentUserLocation;
                        }
                    }

                    Map.OnResume();
                    //                  Map.OnEnterAmbient(null);
                });
            });

            // Set the map type back to normal.
            _activity.RunOnUiThread(() => { GMap.MapType = GoogleMap.MapTypeNormal; });
        }
        /*
         *      private void SetMapLocation()
         *      {
         *          if (GMap == null) return;
         *
         *          var location = Map.Tag as LatLng;
         *          if (location == null && _userLocation == null) return;
         *
         *          // Calculate the map position and zoom/size
         *          CameraUpdate cameraUpdate = null;
         *          if (_userLocation == null)
         *              cameraUpdate = CameraUpdateFactory.NewLatLngZoom(location, Constants.DefaultResponseMapZoom);
         *          else if (location == null)
         *              cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_userLocation, Constants.DefaultResponseMapZoom);
         *          else
         *          {
         *              var latDelta = Math.Abs(location.Latitude - _userLocation.Latitude);
         *              var longDelta = Math.Abs(location.Longitude - _userLocation.Longitude);
         *              var minLat = Math.Min(location.Latitude, _userLocation.Latitude) - latDelta / 4;
         *              var maxLat = Math.Max(location.Latitude, _userLocation.Latitude) + latDelta / 4;
         *              var minLong = Math.Min(location.Longitude, _userLocation.Longitude) - longDelta / 4;
         *              var maxLong = Math.Max(location.Longitude, _userLocation.Longitude) + longDelta / 4;
         *
         *              LatLngBounds.Builder builder = new LatLngBounds.Builder();
         *              builder.Include(new LatLng(minLat, minLong));
         *              builder.Include(new LatLng(maxLat, maxLong));
         *              // shouldn't need to include these but we'll include them just in case
         *              builder.Include(new LatLng(location.Latitude, location.Longitude));
         *              builder.Include(new LatLng(_userLocation.Latitude, _userLocation.Longitude));
         *              LatLngBounds bounds = builder.Build();
         *              cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 0);
         *          }
         *
         *          // Set the map position
         *          GMap.MoveCamera(cameraUpdate);
         *
         *          // Add a markers
         *          if (location != null)
         *          {
         *              var markerOptions = new MarkerOptions();
         *              markerOptions.SetPosition(location);
         *              if (_colorHue > -1)
         *              {
         *                  var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(_colorHue);
         *                  markerOptions.SetIcon(bmDescriptor);
         *              }
         *              GMap.AddMarker(markerOptions);
         *          }
         *          if (_userLocation != null)
         *          {
         *              var markerOptions0 = new MarkerOptions();
         *              markerOptions0.SetPosition(_userLocation);
         *              markerOptions0.SetIcon(UserLocationIcon);
         *              markerOptions0.Anchor(0.5f, 0.5f);
         *              GMap.AddMarker(markerOptions0);
         *          }
         *
         *          // Set the map type back to normal.
         *          GMap.MapType = GoogleMap.MapTypeNormal;
         *      }
         */



        private void DrawMap(bool moveMap = true)
        {
            if (GMap == null)
            {
                return;
            }

            if (_eventLocation == null && _userLocation == null)
            {
                return;
            }

            // Calculate the map position and zoom/size
            CameraUpdate cameraUpdate = null;

            if (moveMap)
            {
                if (_userLocation == null)
                {
                    cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_eventLocation, Constants.DefaultResponseMapZoom);
                }
                else if (_eventLocation == null)
                {
                    cameraUpdate = CameraUpdateFactory.NewLatLngZoom(_userLocation, Constants.DefaultResponseMapZoom);
                }
                else
                {
                    _latDelta  = Math.Abs(_eventLocation.Latitude - _userLocation.Latitude);
                    _longDelta = Math.Abs(_eventLocation.Longitude - _userLocation.Longitude);
                    var minLat  = Math.Min(_eventLocation.Latitude, _userLocation.Latitude) - _latDelta / 4;
                    var maxLat  = Math.Max(_eventLocation.Latitude, _userLocation.Latitude) + _latDelta / 4;
                    var minLong = Math.Min(_eventLocation.Longitude, _userLocation.Longitude) - _longDelta / 4;
                    var maxLong = Math.Max(_eventLocation.Longitude, _userLocation.Longitude) + _longDelta / 4;

                    LatLngBounds.Builder builder = new LatLngBounds.Builder();
                    builder.Include(new LatLng(minLat, minLong));
                    builder.Include(new LatLng(maxLat, maxLong));
                    // shouldn't need to include these but we'll include them just in case
                    builder.Include(new LatLng(_eventLocation.Latitude, _eventLocation.Longitude));
                    builder.Include(new LatLng(_userLocation.Latitude, _userLocation.Longitude));
                    LatLngBounds bounds = builder.Build();
                    cameraUpdate = CameraUpdateFactory.NewLatLngBounds(bounds, 0);
                }
                // Set the map position
                GMap.MoveCamera(cameraUpdate);
            }

            // Add a markers
            if (_eventLocation != null)
            {
                if (_eventLocationMarker == null)
                {
                    var markerOptions = new MarkerOptions();
                    markerOptions.SetPosition(_eventLocation);
                    if (_colorHue > -1)
                    {
                        var bmDescriptor = BitmapDescriptorFactory.DefaultMarker(_colorHue);
                        markerOptions.SetIcon(bmDescriptor);
                    }
                    _eventLocationMarker = GMap.AddMarker(markerOptions);
                }
                else
                {
                    _eventLocationMarker.Position = _eventLocation;
                }
            }
            if (_userLocation != null)
            {
                if (_userLocationMarker == null)
                {
                    var markerOptions0 = new MarkerOptions();
                    markerOptions0.SetPosition(_userLocation);
                    markerOptions0.SetIcon(UserLocationIcon);
                    markerOptions0.Anchor(0.5f, 0.5f);
                    _userLocationMarker = GMap.AddMarker(markerOptions0);
                }
                else
                {
                    _userLocationMarker.Position = _userLocation;
                }
            }

            // Set the map type back to normal.
            GMap.MapType = GoogleMap.MapTypeNormal;
        }
        void SetupMap()
        {
            if (mapFrag.View.Width == 0)
            {
                mapFrag.View.PostDelayed(SetupMap, 500);
                return;
            }
            if (viewModel.Trip == null || viewModel.Trip.Points == null || viewModel.Trip.Points.Count == 0)
            {
                return;
            }

            var start = viewModel.Trip.Points[0];
            var end   = viewModel.Trip.Points[viewModel.Trip.Points.Count - 1];

            seekBar.Max              = viewModel.Trip.Points.Count - 1;
            seekBar.ProgressChanged += SeekBar_ProgressChanged;

            var logicalDensity  = Resources.DisplayMetrics.Density;
            var thicknessCar    = (int)Math.Ceiling(26 * logicalDensity + .5f);
            var thicknessPoints = (int)Math.Ceiling(20 * logicalDensity + .5f);

            var b         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_car_blue) as BitmapDrawable;
            var finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessCar, thicknessCar, false);

            var car = new MarkerOptions();

            car.SetPosition(new LatLng(start.Latitude, start.Longitude));
            car.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
            car.Anchor(.5f, .5f);

            b         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_start_point) as BitmapDrawable;
            finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);

            var startMarker = new MarkerOptions();

            startMarker.SetPosition(new LatLng(start.Latitude, start.Longitude));
            startMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
            startMarker.Anchor(.5f, .5f);

            b         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_end_point) as BitmapDrawable;
            finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);

            var endMarker = new MarkerOptions();

            endMarker.SetPosition(new LatLng(end.Latitude, end.Longitude));
            endMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(finalIcon));
            endMarker.Anchor(.5f, .5f);

            b         = ContextCompat.GetDrawable(this, Resource.Drawable.ic_tip) as BitmapDrawable;
            finalIcon = Bitmap.CreateScaledBitmap(b.Bitmap, thicknessPoints, thicknessPoints, false);
            var poiIcon = BitmapDescriptorFactory.FromBitmap(finalIcon);

            foreach (var poi in viewModel.POIs)
            {
                var poiMarker = new MarkerOptions();
                poiMarker.SetPosition(new LatLng(poi.Latitude, poi.Longitude));
                poiMarker.SetIcon(poiIcon);
                poiMarker.Anchor(.5f, .5f);
                map.AddMarker(poiMarker);
            }


            var points      = viewModel.Trip.Points.Select(s => new LatLng(s.Latitude, s.Longitude)).ToArray();
            var rectOptions = new PolylineOptions();

            rectOptions.Add(points);
            rectOptions.InvokeColor(ContextCompat.GetColor(this, Resource.Color.primary_dark));
            map.AddPolyline(rectOptions);


            map.AddMarker(startMarker);
            map.AddMarker(endMarker);

            carMarker = map.AddMarker(car);

            var boundsPoints = new LatLngBounds.Builder();

            foreach (var point in points)
            {
                boundsPoints.Include(point);
            }

            var bounds = boundsPoints.Build();

            map.MoveCamera(CameraUpdateFactory.NewLatLngBounds(bounds, 64));

            map.MoveCamera(CameraUpdateFactory.NewLatLng(carMarker.Position));


            seekBar.Enabled = true;
        }
예제 #30
0
        async Task setCustomizeIcon(UbicacionDTO[] coordenadasArray, bool pubnubResponse)
        {
            await Task.Run(() => {
                int contador = 1;
                foreach (var coordenadas in coordenadasArray)
                {
                    LatLng ubicacion      = new LatLng((double)coordenadas.Latitud, (double)coordenadas.Longitud);
                    LastLocation newPoint = new LastLocation("", ubicacion);
                    bool mustLeaveIcon1KM = (lastMarkerPubNub != null && lastPointMarker1KM.DistanceTo(newPoint) > 500);
                    int ResourceIDFlechas;
                    int ResourceIDCarro;
                    var marker = new MarkerOptions();

                    if (coordenadas.Velocidad > 90)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Marron;
                        ResourceIDCarro   = Resource.Drawable.icono_rojo;
                    }
                    else if (coordenadas.Velocidad <= 90 && coordenadas.Velocidad > 70)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Rosada;
                        ResourceIDCarro   = Resource.Drawable.icono_rosado;
                    }
                    else if (coordenadas.Velocidad <= 70 && coordenadas.Velocidad > 40)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Verde;
                        ResourceIDCarro   = Resource.Drawable.icono_verde;
                    }
                    else if (coordenadas.Velocidad <= 40 && coordenadas.Velocidad > 10)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Aqua;
                        ResourceIDCarro   = Resource.Drawable.icono_azul_claro;
                    }
                    else if (coordenadas.Velocidad <= 10 && coordenadas.Velocidad > 1)
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Azul;
                        ResourceIDCarro   = Resource.Drawable.icono_azul_oscuro;
                    }
                    else
                    {
                        ResourceIDFlechas = Resource.Drawable.Flecha_Morada;
                        ResourceIDCarro   = Resource.Drawable.icono_morado;
                    }

                    marker.SetPosition(ubicacion);
                    marker.SetRotation((float)coordenadas.Bearing);
                    marker.Anchor(0.5f, 0.5f);
                    marker.SetTitle(coordenadas.Nombre_Usuario);
                    marker.SetSnippet("Tiempo: " + coordenadas.Tiempo + "*Latitud: " + coordenadas.Latitud + "*Longitud: " + coordenadas.Longitud + "*Velocidad: " + string.Format("{0:0.##}", coordenadas.Velocidad) + "*Direccion: " + coordenadas.Direccion);

                    if (pubnubResponse == false)
                    {
                        using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                        {
                            using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                            {
                                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                            }
                        }
                    }

                    if (coordenadasArray.Count() == contador || pubnubResponse == true)
                    {
                        using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDCarro))
                        {
                            using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(27, this), (int)convertDpToPixel(37, this), false))
                            {
                                marker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                            }
                        }
                    }

                    if (pubnubResponse)
                    {
                        RunOnUiThread(() =>
                        {
                            googleMap.AddPolyline(mPolylineOptions.Add(ubicacion));

                            if (mustLeaveIcon1KM)
                            {
                                using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                                {
                                    using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                                    {
                                        lastMarkerPubNub.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                                        lastPointMarker1KM = newPoint;
                                    }
                                }
                            }
                            else if (lastMarkerPubNub != null)
                            {
                                lastMarkerPubNub.Remove();
                            }
                            else
                            {
                                lastPointMarker1KM = new LastLocation("", ubicacion);
                                using (Bitmap icon = BitmapFactory.DecodeResource(Resources, ResourceIDFlechas))
                                {
                                    using (Bitmap bhalfsize = Bitmap.CreateScaledBitmap(icon, (int)convertDpToPixel(23, this), (int)convertDpToPixel(33, this), false))
                                    {
                                        lastMarker.SetIcon(BitmapDescriptorFactory.FromBitmap(bhalfsize));
                                    }
                                }
                            }
                            googleMap.AnimateCamera(CameraUpdateFactory.NewLatLng(ubicacion));
                            lastMarkerPubNub = googleMap.AddMarker(marker);
                        });
                    }
                    else
                    {
                        RunOnUiThread(() =>
                        {
                            lastMarker = googleMap.AddMarker(marker);
                        });
                    }
                    contador += 1;
                }
            });
        }