Beispiel #1
0
        private void MoveMapPosition()
        {
            try
            {
                double ZoomOnData  = 1;
                double ZoomOffData = 400;
                switch (Device.OS)
                {
                case TargetPlatform.Android:
                    //
                    if (_casePosition != null)
                    {
                        SplitView.MapView.MoveToRegion(new GoogleMap.Position(_casePosition.Latitude, _casePosition.Longitude), GoogleMap.Distance.FromKilometers(ZoomOnData));
                    }
                    else if (AppContext.AppContext.LstGooglePin.Count > 0)
                    {
                        SplitView.MapView.MoveToRegion(AppContext.AppContext.LstGooglePin.FirstOrDefault().Position, GoogleMap.Distance.FromKilometers(ZoomOnData));
                    }
                    else
                    {
                        SplitView.MapView.MoveToRegion(UK_GMPosition, GoogleMap.Distance.FromKilometers(ZoomOffData));
                    }
                    //
                    break;

                case TargetPlatform.Windows:
                case TargetPlatform.iOS:
                    //
                    if (_casePosition != null)
                    {
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            _mapview?.ClearPin();
                            _mapview?.LoadPin(new CustomPin()
                            {
                                ImageUrl = "locCurrentPin.png",
                                Pin      = new XamarinMaps.Pin()
                                {
                                    //To show the Location icon
                                    Address  = "Current Location",
                                    Position = new XamarinMaps.Position(_casePosition.Latitude, _casePosition.Longitude),
                                    Label    = "",
                                    //
                                }
                            });
                            _mapview?.MoveToRegion(new XamarinMaps.Position(_casePosition.Latitude, _casePosition.Longitude), XamarinMaps.Distance.FromKilometers(ZoomOnData));
                        });

                        //Device.BeginInvokeOnMainThread(() =>
                        //	{
                        //		_mapview?.ClearPin();
                        //		AppContext.AppContext.CurrentLocation = new CustomPin
                        //		{
                        //		ImageUrl = "locCurrentPin.png",
                        //			Pin = new XamarinMaps.Pin()
                        //			{
                        //				Position = new XamarinMaps.Position(_casePosition.Latitude, _casePosition.Longitude),
                        //				Label = "",
                        //			}

                        //		};
                        //		_mapview.MoveToRegion(new XamarinMaps.Position(_casePosition.Latitude, _casePosition.Longitude), XamarinMaps.Distance.FromKilometers(ZoomOnData));
                        //	});
                    }
                    else if (AppContext.AppContext.LstCustomPin.Count > 0)
                    {
                        _mapview.MoveToRegion(AppContext.AppContext.LstCustomPin.FirstOrDefault().Pin.Position, XamarinMaps.Distance.FromKilometers(ZoomOnData));
                    }
                    else
                    {
                        _mapview.MoveToRegion(UK_XFPosition, XamarinMaps.Distance.FromKilometers(ZoomOffData));
                    }
                    //
                    break;
                    //case TargetPlatform.iOS:
                    //
                    //if (_casePosition != null)
                    //    _mapview.MoveToRegion(new XamarinMaps.Position(_casePosition.Latitude, _casePosition.Longitude), XamarinMaps.Distance.FromKilometers(ZoomOnData));
                    // else if (AppContext.AppContext.LstCustomPin.Count > 0)
                    //     _mapview.MoveToRegion(AppContext.AppContext.LstCustomPin.FirstOrDefault().Pin.Position, XamarinMaps.Distance.FromKilometers(ZoomOnData));
                    // else
                    //    _mapview.MoveToRegion(UK_XFPosition, XamarinMaps.Distance.FromKilometers(ZoomOffData));
                    //
                    // break;
                }
            }
            catch (Exception ex)
            {
                LogTracking.LogTrace(ex.ToString());
            }
        }