public void CenterToCurrentLocation(MKMapView map, Event currentEvent)
        {
            var target        = new CLLocationCoordinate2D(currentEvent.Lat, currentEvent.Long);
            var currentregion = MKCoordinateRegion.FromDistance(target, 9000, 9000);

            map.SetRegion(currentregion, animated: false);
        }
        public void ZoomToCurrentLocation(MKMapView map, CLLocationManager LM)
        {
            var target        = new CLLocationCoordinate2D(LM.Location.Coordinate.Latitude, LM.Location.Coordinate.Longitude);
            var currentregion = MKCoordinateRegion.FromDistance(target, 15000, 15000);

            map.SetRegion(currentregion, animated: true);
        }
Example #3
0
        public void setUpMapView()
        {
            // set the map view
            mapView                   = new MKMapView(UIScreen.MainScreen.Bounds);
            mapView.MapType           = MKMapType.Standard;
            mapView.ShowsUserLocation = true;
            View.AddSubview(mapView);
            // Add annotations
            var userCoordinate      = new CLLocationCoordinate2D(-35.3160, 149.1070);
            var currentUserLocation = new MKPointAnnotation()
            {
                Title = "Your Location", Coordinate = userCoordinate
            };
            var driverUserLocation = new DriverAnnotation(("Driver's location"), new CLLocationCoordinate2D(-35.3169, 149.1075));

            mapView.AddAnnotation(currentUserLocation);
            mapView.AddAnnotation(driverUserLocation);
            // set the map delegate
            mapDelegate      = new MapViewDelegate();
            mapView.Delegate = mapDelegate;
            // Add map center
            const double lat       = -35.3160;
            const double lon       = 149.1070;
            var          mapCenter = new CLLocationCoordinate2D(lat, lon);
            var          mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 100, 100);

            mapView.CenterCoordinate = mapCenter;
            mapView.Region           = mapRegion;
        }
        private void showUserMap()
        {
            map.MapType           = MKMapType.HybridFlyover;
            map.ShowsUserLocation = true;
            map.ZoomEnabled       = true;
            map.ScrollEnabled     = true;
            map.ShowsBuildings    = true;
            map.PitchEnabled      = true;
            map.ShowsCompass      = false;
            double lat = 30.2652233534254;
            double lon = -97.73815460962083;
            CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon);
            CLLocationCoordinate2D viewPoint = new CLLocationCoordinate2D(lat + 0.0050, lon - 0.0072);
            MKCoordinateRegion     mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 1500, 1500);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;
            var camera = MKMapCamera.CameraLookingAtCenterCoordinate(mapCenter, viewPoint, 500);

            map.Camera   = camera;
            mapDelegate  = new MapDelegate();
            map.Delegate = mapDelegate;
            askUserPermissions();

            var tapRecogniser     = new UITapGestureRecognizer(this, new Selector("MapTapSelector:"));
            var longTapRecogniser = new UILongPressGestureRecognizer(this, new Selector("MapLongTapSelector:"));

            map.AddGestureRecognizer(tapRecogniser);
            map.AddGestureRecognizer(longTapRecogniser);
            var hotelOverlay = MKCircle.Circle(mapCenter, 1000);

            map.AddOverlay(hotelOverlay);
        }
        public void check(double lon, double lat)
        {
            var mapCenter = new CLLocationCoordinate2D(lat, lon);
            var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 3000, 3000);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;
            if ((lon <= ((-34 * 0.0005) - 106.48694)) && (lat >= ((15 * 0.0005) + 31.739444)) && fuera)
            {
                fuera = false;

                var notification = new UILocalNotification();

                // set the fire date (the date time in which it will fire)
                notification.FireDate = NSDate.Now.AddSeconds(5);                 //DateTime.Now.AddSeconds(10));
                notification.TimeZone = NSTimeZone.DefaultTimeZone;
                // configure the alert stuff
                notification.AlertTitle  = "Peligro";
                notification.AlertAction = "Alert Action";
                notification.AlertBody   = "¡Has entrado en una zona de peligro!";

                notification.UserInfo = NSDictionary.FromObjectAndKey(new NSString("UserInfo for notification"), new NSString("Notification"));

                notification.SoundName = UILocalNotification.DefaultSoundName;

                // schedule it
                UIApplication.SharedApplication.ScheduleLocalNotification(notification);
            }
        }
Example #6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            locationManager.RequestWhenInUseAuthorization();

            // set map type and show user location
            map.MapType           = MKMapType.Standard;
            map.ShowsUserLocation = true;

            map.Bounds = View.Bounds;

            // set map center and region
            const double lat       = 42.374260;
            const double lon       = -71.120824;
            var          mapCenter = new CLLocationCoordinate2D(lat, lon);
            var          mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000);

            //map.CenterCoordinate = mapCenter;
            //map.Region = mapRegion;

            // add an annotation
            map.AddAnnotation(new MKPointAnnotation {
                Title      = "MyAnnotation",
                Coordinate = new CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // set the map delegate
            mapDel       = new MyMapDelegate();
            map.Delegate = mapDel;

            // add a custom annotation
            map.AddAnnotation(new MonkeyAnnotation("Xamarin", mapCenter));

            // add an overlay
            var circleOverlay = MKCircle.Circle(mapCenter, 1000);

            map.AddOverlay(circleOverlay);

            var searchResultsController = new SearchResultsViewController(map);


            var searchUpdater = new SearchResultsUpdator();

            searchUpdater.UpdateSearchResults += searchResultsController.Search;

            //add the search controller
            searchController = new UISearchController(searchResultsController)
            {
                SearchResultsUpdater = searchUpdater
            };

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder    = "Enter a search query";

            searchController.HidesNavigationBarDuringPresentation = false;
            NavigationItem.TitleView   = searchController.SearchBar;
            DefinesPresentationContext = true;
        }
Example #7
0
        void GetAnnotationOfStation()
        {
            if (ActiveStation != null)
            {
                double            result;
                MKPointAnnotation anno = new MKPointAnnotation();
                var coord = anno.Coordinate;
                if (double.TryParse(ActiveStation.Latitude, out result))
                {
                    //anno.Coordinate.Latitude = result;
                    coord.Latitude = result;
                }

                if (double.TryParse(ActiveStation.Longitude, out result))
                {
                    //anno.Coordinate.Longitude = result;
                    coord.Longitude = result;
                }
                anno.Coordinate = coord;
                mapView.AddAnnotation(anno);

                var region = MKCoordinateRegion.FromDistance(anno.Coordinate, 1000, 1000);
                mapView.SetRegion(region, true);
            }
        }
Example #8
0
        protected void AgregoMapa()
        {
            map.MapType = MKMapType.Standard;
            map.Bounds  = UIScreen.MainScreen.Bounds;           //full screen baby

            map.ShowsUserLocation = false;

            MKReverseGeocoder geo      = new MKReverseGeocoder(locationManager.Location.Coordinate);
            CLGeocoder        geocoder = new CLGeocoder();

            Task.Factory.StartNew(async() =>
            {
                var res = await geocoder.ReverseGeocodeLocationAsync(locationManager.Location);
                Console.WriteLine(res[0].AdministrativeArea);

                pais   = res[0].Country;
                ciudad = res[0].Locality;
            });

            // centro el mapa y pongo el zoom en la region
            mapCenter = new CLLocationCoordinate2D(locationManager.Location.Coordinate.Latitude,
                                                   locationManager.Location.Coordinate.Longitude);
            var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 2000, 2000);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;
        }
Example #9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            mapView = new MKMapView(View.Bounds);
            mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            mapView.MapType          = MKMapType.Standard;      // this is the default
            View.AddSubview(mapView);

            double latitude  = 50.846732;
            double longitude = 4.352413;

            var raysPlace = new CLLocationCoordinate2D(latitude, longitude);

            var zoomRegion = MKCoordinateRegion.FromDistance(raysPlace, 2000, 2000);

            mapView.CenterCoordinate = raysPlace;
            mapView.Region           = zoomRegion;

            mapView.Delegate = new RayMapDelegate();

            //Request permission to access device location - necessary on iOS 8.0 and above
            //Don't forget to set NSLocationWhenInUseUsageDescription in Info.plist
            locationManager.RequestWhenInUseAuthorization();

            mapView.ShowsUserLocation = true;

            mapView.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Ray's Hot Dogs",
                Coordinate = new CLLocationCoordinate2D(latitude, longitude)
            });

            mapView.AddAnnotation(new RayAnnotation("Ray's Hot Dogs", raysPlace));
        }
Example #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            mapView = new MKMapView(View.Bounds);
            mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            mapView.MapType          = MKMapType.Standard;
            View.AddSubview(mapView);

            double latitude  = 50.846732;
            double longitude = 4.352413;

            var raysPlace = new CLLocationCoordinate2D(latitude, longitude);

            var zoomRegion = MKCoordinateRegion.FromDistance(raysPlace, 2000, 2000);

            mapView.CenterCoordinate = raysPlace;
            mapView.Region           = zoomRegion;

            mapView.Delegate = new RayMapDelegate();

            locationManager.RequestWhenInUseAuthorization();

            mapView.ShowsUserLocation = true;

            mapView.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Ray's Hot Dogs",
                Coordinate = new CLLocationCoordinate2D(latitude, longitude)
            });

            mapView.AddAnnotation(new RayAnnotation("Ray's Hot Dogs", raysPlace));
        }
Example #11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }



            // change map type, show user location and allow zooming and panning
            map.MapType           = MKMapType.Standard;
            map.ShowsUserLocation = true;
            map.ZoomEnabled       = true;
            map.ScrollEnabled     = true;

            // set map center and region
            double lat = 30.2652233534254;
            double lon = -97.73815460962083;
            CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon);
            MKCoordinateRegion     mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 100, 100);

            map.CenterCoordinate = mapCenter;
            map.Region           = mapRegion;

            // set the map delegate
            mapDelegate  = new MapDelegate();
            map.Delegate = mapDelegate;

            // add a custom annotation at the map center
            map.AddAnnotations(new ConferenceAnnotation("Evolve Conference", mapCenter));

            // add an overlay of the hotel
            MKPolygon hotelOverlay = MKPolygon.FromCoordinates(
                new CLLocationCoordinate2D[] {
                new CLLocationCoordinate2D(30.2649977168594, -97.73863627705),
                new CLLocationCoordinate2D(30.2648461170005, -97.7381627734755),
                new CLLocationCoordinate2D(30.2648355402574, -97.7381750192576),
                new CLLocationCoordinate2D(30.2647791309417, -97.7379872505988),
                new CLLocationCoordinate2D(30.2654525150319, -97.7377341711021),
                new CLLocationCoordinate2D(30.2654807195004, -97.7377994819399),
                new CLLocationCoordinate2D(30.2655089239607, -97.7377994819399),
                new CLLocationCoordinate2D(30.2656428950368, -97.738346460207),
                new CLLocationCoordinate2D(30.2650364981811, -97.7385709662122),
                new CLLocationCoordinate2D(30.2650470749025, -97.7386199493406)
            });

            map.AddOverlay(hotelOverlay);

            UITapGestureRecognizer tap = new UITapGestureRecognizer(g => {
                var pt = g.LocationInView(map);
                CLLocationCoordinate2D tapCoord = map.ConvertPoint(pt, map);

                Console.WriteLine("new CLLocationCoordinate2D({0}, {1}),", tapCoord.Latitude, tapCoord.Longitude);
            });

            map.AddGestureRecognizer(tap);
        }
Example #12
0
        void DrawStepForIndex(int index, bool needZoom = true)
        {
            if (currentDirectionAnnotation != null && index == currentStepIndex)
            {
                return;
            }

            currentStepIndex = index;

//			mapView.RemoveAnnotations (listStepAnnotation.ToArray ());
//			listStepAnnotation.Clear ();

            RouteItem item = ViewModel.Routes [index];
            CLLocationCoordinate2D coordinate = new CLLocationCoordinate2D(item.Lat, item.Long);

//			StepAnnotation annotation = new StepAnnotation ();
//
//			annotation.SetCoordinate (coordinate);
//			mapView.AddAnnotation (annotation);
//			listStepAnnotation.Add (annotation);

            if (needZoom)
            {
                MKCoordinateRegion region = MKCoordinateRegion.FromDistance(coordinate, 400, 400);
                mapView.SetRegion(region, true);
//				mapView.SetCenterCoordinate (coordinate, true);
            }

            if (currentDirectionAnnotation != null)
            {
                mapView.RemoveAnnotation(currentDirectionAnnotation);
            }
            currentDirectionAnnotation = null;

            DirectionAnnotation nextDirectionAnnotation = new DirectionAnnotation();

            nextDirectionAnnotation.SetCoordinate(coordinate);

            if (currentStepIndex < ViewModel.Routes.Count - 1)
            {
                RouteItem nextItem = ViewModel.Routes [index + 1];

                CLLocationCoordinate2D nextCoordinate = new CLLocationCoordinate2D(nextItem.Lat, nextItem.Long);

                nextDirectionAnnotation.CurAngle = CalcBearing(coordinate, nextCoordinate).ToRad();
            }
            else
            {
                if (desCoordinate.IsValid())
                {
                    nextDirectionAnnotation.SetCoordinate(desCoordinate);

                    nextDirectionAnnotation.CurAngle = CalcBearing(coordinate, desCoordinate).ToRad();
                }
            }

            mapView.AddAnnotation(nextDirectionAnnotation);
            currentDirectionAnnotation = nextDirectionAnnotation;
        }
Example #13
0
        private void SetMapCenter(double latitude, double longitude, int distance)
        {
            var mapView = Control;
            var center  = new CLLocationCoordinate2D(latitude, longitude);

            mapView.SetCenterCoordinate(center, true);
            mapView.SetRegion(MKCoordinateRegion.FromDistance(center, distance, distance), true);
        }
        void AnnotateAndZoomToRegion(CLCircularRegion region)
        {
            circleOverlay = MKCircle.Circle(region.Center, region.Radius);
            const double multiplier = MapRegionFraction;
            var          mapRegion  = MKCoordinateRegion.FromDistance(region.Center, region.Radius * multiplier, region.Radius * multiplier);

            MapView.SetRegion(mapRegion, false);
        }
        private void locationUpdated(object sender, CLLocationUpdatedEventArgs e)
        {
            Map.CenterCoordinate = e.NewLocation.Coordinate;
            Map.Region           = MKCoordinateRegion.FromDistance(e.NewLocation.Coordinate, 5000, 5000);

            var annotation = new MapAnnotation("Current Location", e.NewLocation.Coordinate);

            Map.AddAnnotation(annotation);
        }
        public void UpdateMap(bool result)
        {
            GroupTableSource.SelectedIndex = -1;

            // remove existing annotations
            MapView.RemoveAnnotations(MapView.Annotations);

            // set the search results banner appropriately
            if (GroupEntries.Count > 0)
            {
                SearchResultsPrefix.Text = ConnectStrings.GroupFinder_Neighborhood;
                //SearchResultsNeighborhood.Text = GroupEntries[ 0 ].NeighborhoodArea;

                // add an annotation for each position found in the group
                List <IMKAnnotation> annotations = new List <IMKAnnotation>();

                // add an annotation for the source
                MKPointAnnotation sourceAnnotation = new MKPointAnnotation();
                sourceAnnotation.SetCoordinate(new CLLocationCoordinate2D(SourceLocation.Latitude, SourceLocation.Longitude));
                sourceAnnotation.Title    = "";
                sourceAnnotation.Subtitle = "";
                annotations.Add(sourceAnnotation);

                foreach (MobileAppApi.GroupSearchResult entry in GroupEntries)
                {
                    MKPointAnnotation annotation = new MKPointAnnotation();
                    annotation.SetCoordinate(new CLLocationCoordinate2D(entry.Latitude, entry.Longitude));
                    annotation.Title    = entry.Name;
                    annotation.Subtitle = string.Format("{0:##.0} {1}", entry.DistanceFromSource, ConnectStrings.GroupFinder_MilesSuffix);
                    annotations.Add(annotation);
                }
                MapView.ShowAnnotations(annotations.ToArray( ), true);
            }
            else
            {
                if (result == true)
                {
                    SearchResultsPrefix.Text       = ConnectStrings.GroupFinder_NoGroupsFound;
                    SearchResultsNeighborhood.Text = string.Empty;

                    // since there were no groups, revert the map to whatever specified area
                    MKCoordinateRegion region = MKCoordinateRegion.FromDistance(new CLLocationCoordinate2D(
                                                                                    ConnectConfig.GroupFinder_DefaultLatitude,
                                                                                    ConnectConfig.GroupFinder_DefaultLongitude),
                                                                                ConnectConfig.GroupFinder_DefaultScale_iOS,
                                                                                ConnectConfig.GroupFinder_DefaultScale_iOS);
                    MapView.SetRegion(region, true);
                }
                else
                {
                    SearchResultsPrefix.Text       = ConnectStrings.GroupFinder_NetworkError;
                    SearchResultsNeighborhood.Text = string.Empty;
                }
            }

            UpdateResultsBanner( );
        }
Example #17
0
        public override void Refresh(ChallengeResponseModel challengeResponse)
        {
            Crashlytics.Instance.Log("ChallengeDetailViewController_Refresh()");
            base.Refresh(challengeResponse);

            if (challengeResponse == null)
            {
                return;
            }

            Challenge             = challengeResponse.Challenge;
            TimeText.Text         = Challenge.NextEventCountDown;
            PointsText.Text       = "+" + Challenge.PointValue.ToString() + " pts";
            ChallengeTextLbl.Text = Challenge.Name;

            var navigationDelegate = new ChallengeDetailWebViewNavigationDelegate();

            navigationDelegate.NavigationFinished += SetupConstraint;
            this.WebView.NavigationDelegate        = navigationDelegate;
            WebView.LoadHtmlString(Challenge.Desc, null);
            ImageService.Instance.LoadUrl(Challenge.Image).Into(ChallengeImage);

            if (!DidSetupMap && Challenge.LocationLat != null && Challenge.LocationLong != null)
            {
                ChallengeImage.Hidden = true;
                vImagePlaceholder.RemoveConstraint(cnImagePlaceholderAspect);
                vImagePlaceholder.AddConstraint(cnImagePlaceholderAspect = NSLayoutConstraint.Create(vImagePlaceholder, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 0));

                double radius = Challenge.RadiusMeters ?? 100.0;
                if (radius > 6000000)
                {
                    radius = 6000000;
                }
                double mapRegion = radius * 2.5;

                CLLocationCoordinate2D mapCoordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapViewBase.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, mapRegion, mapRegion), true);

                MKCircle circle = MKCircle.Circle(mapCoordinate, radius);
                MapViewBase.AddOverlay(circle);

                MKPointAnnotation annotation = new MKPointAnnotation();
                annotation.Coordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapViewBase.AddAnnotation(annotation);

                DidSetupMap = true;
            }
            else
            {
                MapViewBase.Hidden = true;
                paddingMap.RemoveConstraint(cnMapPlaceholderAspect);
                paddingMap.AddConstraint(cnMapPlaceholderAspect = NSLayoutConstraint.Create(paddingMap, NSLayoutAttribute.Height, NSLayoutRelation.Equal, 1, 0));
            }

            CheckStatus();
        }
Example #18
0
 public void SetRegion(MapCoordinate centerCoord, double visibleMeters, bool animated = false)
 {
     setRegionCoord    = centerCoord;
     setRegionDistance = visibleMeters;
     if (map == null)
     {
         return;
     }
     map.SetRegion(MKCoordinateRegion.FromDistance(GetCoord(centerCoord), visibleMeters, visibleMeters), animated);
 }
        void SetMapRegion()
        {
            var placePosition = viewModel.Position;
            var userPosition  = new CLLocationCoordinate2D(placePosition.Latitude, placePosition.Longitude);
            var distance      = viewModel.Place.GetDistance(placePosition.Latitude, placePosition.Longitude, GeolocationUtils.DistanceUnit.Kilometers);

            distance += 6;             // Add more distance units to display map annotations in screen bounds
            var region = MKCoordinateRegion.FromDistance(userPosition, distance * MetersInKilometer, distance * MetersInKilometer);

            MapView.SetRegion(region);
        }