Example #1
0
        private async void getMyLocation()
        {
            var locator  = CrossGeolocator.Current;
            var location = await locator.GetPositionAsync(TimeSpan.FromTicks(10000));

            Position position = new Position(location.Latitude, location.Longitude);

            map.MoveToRegion(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude), Xamarin.Forms.Maps.Distance.FromMiles(3)));
        }
        private async Task InitializeGoogleMap()
        {
            Map = new Xamarin.Forms.Maps.Map();
            Map.HasZoomEnabled = true;
            Map.IsShowingUser  = true;

            var currentLoc = await GetUserLocation();

            if (currentLoc != null)
            {
                var pos = new Xamarin.Forms.Maps.Position(currentLoc.Latitude, currentLoc.Longitude);

                Map.Pins.Add(new Xamarin.Forms.Maps.Pin
                {
                    Label    = $"Here I am",
                    Position = pos,
                });
            }

            //Defaults to current
            //Map.
            Map.MoveToRegion(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(
                                 new Xamarin.Forms.Maps.Position(28.644800, 77.216721), Xamarin.Forms.Maps.Distance.FromKilometers(5000)));
        }
Example #3
0
        void moveMap(bool updateZoom)
        {
            if (this.currentLocation == null)
            {
                TraceHelper.TraceInfoForResponsiveness("moveMap. currentLocation=null");
            }
            else
            {
                TraceHelper.TraceInfoForResponsiveness("moveMap. currentLocation=" + this.currentLocation.ToString());
            }

            /// what should be the map center point?
            ///
            Location location = this.currentLocation;

            if (location == null)
            {
                // point to Portland
                double latitude_Portland   = 45.53;
                double longtitude_Portland = -122.68;
                location = new Location(latitude_Portland, longtitude_Portland);
            }

            /// what should be the map "radius"?
            ///
            double newRadiusInMeters;

            if (this.radiusInMeters != null && updateZoom == false)
            {
                // use previous radius
                newRadiusInMeters = radiusInMeters.Value;
            }
            else
            {
                if (this.CurrentCommunity != null && this.CurrentCommunity.IsPlanetEarth)
                {
                    // Planet Earth level
                    newRadiusInMeters = 5000000;
                }
                else if (this.CurrentCommunity != null && this.CurrentCommunity.MetroID == 0 && this.CurrentCommunity.Country != null)
                {
                    // country-level
                    Country country = this.CurrentCommunity.Country;
                    if (country.AreaSize == CountrySizeEnum.Regular)
                    {
                        newRadiusInMeters = 800000;
                    }
                    else
                    {
                        newRadiusInMeters = 5000000;
                    }
                }
                else
                {
                    // city-level
                    newRadiusInMeters = 50000;
                }
            }
            this.radiusInMeters = newRadiusInMeters;

            /// move the map
            ///
            var    loc2 = location.OffsetRoughly(newRadiusInMeters, newRadiusInMeters);
            double lat  = System.Math.Abs(location.Latitude - loc2.Latitude);
            double lon  = System.Math.Abs(location.Longitude - loc2.Longitude);

            this.avoidLoadingVenuesUntilThisTime = DateTime.Now.AddSeconds(2);
            TraceHelper.TraceInfoForResponsiveness("moveMap.MoveToRegion!!! location=" + location.ToString() + "   lat=" + lat + "   lon=" + lon);
            map.MoveToRegion(new Xamarin.Forms.Maps.MapSpan(
                                 new Xamarin.Forms.Maps.Position(location.Latitude, location.Longitude),
                                 lat, lon));

            this.needToSearchAgain = true;
        }