Example #1
0
        private void OnLocationRequestResult(object sender, LocationCallbackResultEventArgs e)
        {
            if (e.Result.Locations.Count < 1)
            {
                return;
            }
            Location accurateLocation = e.Result.Locations.Aggregate((location1, location2) =>
                                                                     location1.Accuracy < location2.Accuracy ? location1 : location2);

            if (OldLocation == null)
            {
                OldLocation = accurateLocation;
            }

            float t = accurateLocation.Time - OldLocation.Time;

            if (accurateLocation.Accuracy < OldLocation.Accuracy || t * 1000 > 300)
            {
                OldLocation = accurateLocation;
            }

            if (accurateLocation.Accuracy > 30)
            {
                return;
            }

            OldLocation = accurateLocation;
            var addressResultReceiver = new MapPageRendererAddressResultReceiver(new Handler(), this);

            StartAddressIntentService(addressResultReceiver, accurateLocation);
        }
Example #2
0
        public override void AddView(AView child)
        {
            if (child is CoordinatorLayout)
            {
                base.AddView(child);
                return;
            }

            ((ViewGroup)child).LayoutParameters =
                new CoordinatorLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
            MainViewGroup = (ViewGroup)child;
            AndroidCoordinatorLayout.FindViewById <RelativeLayout>(Resource.Id.map_holder)
            .AddView(child);

            for (var i = 0; i < MainViewGroup.ChildCount; i++)
            {
                AView foundChild = MainViewGroup.GetChildAt(i);

                if (!(foundChild is CyclesMapRenderer cyclesMapRenderer))
                {
                    continue;
                }
                CyclesMapView = cyclesMapRenderer;

                CyclesMapView.MapReady += async sender =>
                {
                    if (!MainActivity.IsLocationAccessGranted || !MainActivity.IsLocationEnabled)
                    {
                        return;
                    }

                    Location lastLocation = await FusedLocationProviderClient.GetLastLocationAsync();

                    if (lastLocation == null)
                    {
                        return;
                    }
                    var addressResultReceiver = new MapPageRendererAddressResultReceiver(new Handler(), this);
                    StartAddressIntentService(addressResultReceiver, lastLocation);

                    var latLng = new LatLng(lastLocation.Latitude, lastLocation.Longitude);
                    CameraPosition.Builder builder = CameraPosition.InvokeBuilder();
                    builder.Target(latLng);
                    builder.Zoom(18);
                    CameraPosition cameraPosition = builder.Build();
                    CameraUpdate   cameraUpdate   = CameraUpdateFactory.NewCameraPosition(cameraPosition);

                    CyclesMapView.AnimateCamera(cameraUpdate);
                };
            }
        }