public void DisplayAnnotations(List <IMKAnnotation> annotations, MKMapView mapView)
        {
            List <IMKAnnotation> before = new List <IMKAnnotation>();

            foreach (IMKAnnotation annotation in mapView.Annotations)
            {
                before.Add(annotation);
            }
//            MKUserLocation userLocation = mapView.UserLocation;
//            if (userLocation != null)
//                before.Remove(userLocation);
            List <IMKAnnotation> after  = new List <IMKAnnotation>(annotations);
            List <IMKAnnotation> toKeep = new List <IMKAnnotation>(before);

            toKeep = FBUtils.Intersect(toKeep, after);
            List <IMKAnnotation> toAdd = new List <IMKAnnotation>(after);

            toAdd.RemoveAll((IMKAnnotation obj) =>
            {
                return(toKeep.Contains(obj));
            });
            List <IMKAnnotation> toRemove = new List <IMKAnnotation>(before);

            toRemove.RemoveAll((IMKAnnotation obj) =>
            {
                return(after.Contains(obj));
            });

            NSOperationQueue.MainQueue.AddOperation(delegate()
            {
                mapView.AddAnnotations(toAdd.ToArray());
                mapView.RemoveAnnotations(toRemove.ToArray());
            }
                                                    );
        }
示例#2
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);
        }
示例#3
0
 private void AddAnnotation(double latitude, double longitude)
 {
     _mapView.AddAnnotations(new MKPointAnnotation()
     {
         Title      = "MyAnnotation",
         Coordinate = new CLLocationCoordinate2D(latitude, longitude)
     });
 }
示例#4
0
        public void LongPress(UILongPressGestureRecognizer touches)
        {
            if (touches.State == UIGestureRecognizerState.Ended)
            {
                CGPoint location = touches.LocationInView(_map);
                CLLocationCoordinate2D coordinate = _map.ConvertPoint(location, _map);

                _marcerRow           = new MapMarkerEntity();
                _marcerRow.Latitude  = coordinate.Latitude;
                _marcerRow.Longitude = coordinate.Longitude;

                ViewModel.SaveMarkerInList(_marcerRow);

                _map.AddAnnotations(new MKPointAnnotation()
                {
                    Title      = Constants.MapMarker,
                    Coordinate = new CLLocationCoordinate2D(coordinate.Latitude, coordinate.Longitude)
                });
            }
        }
示例#5
0
        private void LongPress(UILongPressGestureRecognizer gesture)
        {
            _mKMapView.RemoveAnnotations(_mKMapView.Annotations);
            CGPoint touchPoint = gesture.LocationInView(_mKMapView);
            CLLocationCoordinate2D touchMapCoordinate = _mKMapView.ConvertPoint(touchPoint, _mKMapView);

            MKAnnotationClass annotation = new MKAnnotationClass();

            annotation.Coordinate2D = touchMapCoordinate;
            _lalitude  = annotation.Coordinate2D.Latitude;
            _longitude = annotation.Coordinate2D.Longitude;
            _customMap.UserLalitude  = _lalitude;
            _customMap.UserLongitude = _longitude;
            _mKMapView.AddAnnotation(annotation);

            _mKMapView.AddAnnotations(new MKPointAnnotation()
            {
                Coordinate = new CLLocationCoordinate2D(_lalitude, _longitude)
            });
        }
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            //Item der Map hinzufügen
            CLLocationCoordinate2D coord = MapItems[indexPath.Row].Placemark.Location.Coordinate;

            mapView.AddAnnotations(new MKPointAnnotation()
            {
                Title      = MapItems[indexPath.Row].Name,
                Coordinate = coord
            });
            mapView.SetCenterCoordinate(coord, true);
            DismissViewController(false, null);
        }
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            // add item to map
            var coordinate = items[indexPath.Row].Placemark.Location.Coordinate;

            map.AddAnnotations(new MKPointAnnotation
            {
                Coordinate = coordinate,
                Title      = items[indexPath.Row].Name,
            });

            map.SetCenterCoordinate(coordinate, true);
            DismissViewController(false, null);
        }
示例#8
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "Map";

            _buttonBack       = new UIButton(UIButtonType.Custom);
            _buttonBack.Frame = new CGRect(0, 0, 40, 40);
            _buttonBack.SetImage(UIImage.FromBundle("icons8-back-filled-30.png"), UIControlState.Normal);
            this.NavigationItem.SetLeftBarButtonItem(new UIBarButtonItem(_buttonBack), false);

            _buttonSavePin       = new UIButton(UIButtonType.Custom);
            _buttonSavePin.Frame = new CGRect(0, 0, 40, 40);
            _buttonSavePin.SetImage(UIImage.FromBundle("baseline_add_location_black_48dp.png"), UIControlState.Normal);
            this.NavigationItem.SetRightBarButtonItem(new UIBarButtonItem(_buttonSavePin), false);
            _buttonSavePin.TouchUpInside += ButtonGoogleMarkerSaveClick;

            MapViewIOS               = new MKMapView();
            View                     = MapViewIOS;
            MapViewIOS.ZoomEnabled   = true;
            MapViewIOS.ScrollEnabled = true;
            CLLocationManager locationManager = new CLLocationManager();

            locationManager.RequestWhenInUseAuthorization();
            MapViewIOS.ShowsUserLocation = true;

            var longGesture = new UILongPressGestureRecognizer(LongPress);

            longGesture.MinimumPressDuration = 1.5;
            MapViewIOS.AddGestureRecognizer(longGesture);

            MapViewIOS.GetViewForAnnotation += GetViewForAnnotation;

            if (ViewModel.LalitudeGoogleMarker != 0)
            {
                _lalitude  = this.ViewModel.LalitudeGoogleMarker;
                _longitude = this.ViewModel.LongitudeGoogleMarker;
                MapViewIOS.AddAnnotations(new MKPointAnnotation()
                {
                    Coordinate = new CLLocationCoordinate2D(_lalitude, _longitude)
                });
            }

            var set = this.CreateBindingSet <MapsView, MapsViewModel>();

            set.Bind(_buttonBack).To(vm => vm.BackTaskCommand);
            set.Bind(_buttonSavePin).To(vm => vm.SaveGoogleMapPointCommand);
            set.Apply();
        }
示例#9
0
            public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                // add item to map
                CLLocationCoordinate2D coord = MapItems[indexPath.Row].Placemark.Location.Coordinate;

                map.AddAnnotations(new MKPointAnnotation()
                {
                    Title      = MapItems[indexPath.Row].Name,
                    Coordinate = coord
                });
                map.SetCenterCoordinate(coord, true);

                CLLocationCoordinate2D coords  = map.UserLocation.Coordinate;
                NSDictionary           marker1 = new NSDictionary();
                var orignPlaceMark             = new MKPlacemark((coords), marker1);
                var sourceItem = new MKMapItem(orignPlaceMark);


                var destPlaceMark = new MKPlacemark((coord), marker1);
                var destItem      = new MKMapItem(destPlaceMark);

                var go = new MKDirectionsRequest
                {
                    Source                  = sourceItem,
                    Destination             = destItem,
                    RequestsAlternateRoutes = true
                };

                var line = new MKDirections(go);

                line.CalculateDirections((response, error) =>
                {
                    if (error != null)
                    {
                        Console.WriteLine(error.LocalizedDescription);
                    }
                    else
                    {
                        foreach (var route in response.Routes)
                        {
                            map.AddOverlay(route.Polyline);
                        }
                    }
                    var save = new NSString();
                });

                DismissViewController(false, null);
            }
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            // add item to map
            var coordinate = items[indexPath.Row].Placemark.Location.Coordinate;

            map.AddAnnotations(new MKPointAnnotation
            {
                Coordinate = coordinate,
                Title      = items[indexPath.Row].Name,
            });
            showDirection(new CLLocationCoordinate2D(-35.3160, 149.1070), coordinate);
            showDirection(new CLLocationCoordinate2D(-35.3169, 149.1075), new CLLocationCoordinate2D(-35.3160, 149.1070));
            createUsersDetails(map);
            map.SetCenterCoordinate(coordinate, true);
            DismissViewController(false, null);
        }
示例#11
0
        protected async void OnMapTapped(UIGestureRecognizer sender)
        {
            CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map);

            map.RemoveAnnotations(map.Annotations);
            map.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Выбранная геопозиция",
                Coordinate = tappedLocationCoord
            });
            int button = await ShowAlert("Вы уверены?", "Выбрать геопозицию?", "Да", "Нет");

            if (button == 0)
            {
                map.RemoveFromSuperview();
            }
        }
示例#12
0
        private void SetUpMapView()
        {
            MapKitView               = new MKMapView();
            View                     = MapKitView;
            MapKitView.ZoomEnabled   = true;
            MapKitView.ScrollEnabled = true;
            CLLocationManager locationManager = new CLLocationManager();

            locationManager.RequestWhenInUseAuthorization();
            MapKitView.ShowsUserLocation = true;

            MapKitView.DidUpdateUserLocation += delegate
            {
                if (MapKitView.UserLocation != null)
                {
                    CLLocationCoordinate2D coordinateUser     = MapKitView.UserLocation.Coordinate;
                    MKCoordinateSpan       coordinateSpanUser = new MKCoordinateSpan(0.02, 0.02);
                    MapKitView.Region = new MKCoordinateRegion(coordinateUser, coordinateSpanUser);
                }
            };
            if (!MapKitView.UserLocationVisible)
            {
                CLLocationCoordinate2D coords = new CLLocationCoordinate2D(49.99181, 36.23572);
                MKCoordinateSpan       span   = new MKCoordinateSpan(0.05, 0.05);
                MapKitView.Region = new MKCoordinateRegion(coords, span);
            }

            var longGesture = new UILongPressGestureRecognizer(LongPress);

            longGesture.MinimumPressDuration = 0.5;
            MapKitView.AddGestureRecognizer(longGesture);

            MapKitView.GetViewForAnnotation += GetViewForAnnotation;

            if (ViewModel.LalitudeMarker != 0)
            {
                _lalitude  = this.ViewModel.LalitudeMarker;
                _longitude = this.ViewModel.LongitudeMarker;
                MapKitView.AddAnnotations(new MKPointAnnotation()
                {
                    Coordinate = new CLLocationCoordinate2D(_lalitude, _longitude)
                });
            }
        }
        private async void GetPosition()
        {
            try
            {
                var locator = CrossGeolocator.Current;
                locator.DesiredAccuracy = 50;

                var position = await locator.GetPositionAsync(TimeSpan.FromSeconds(10));

                lon = position.Longitude.ToString();
                lat = position.Latitude.ToString();
                Debug.WriteLine(lon);
                Debug.WriteLine(lat);
                CLLocationManager locationManager = new CLLocationManager();
                locationManager.RequestWhenInUseAuthorization();
                maps.AddAnnotations(new MKPointAnnotation()
                {
                    Title      = "MyAnnotation",
                    Coordinate = new CLLocationCoordinate2D(Convert.ToDouble(lon), Convert.ToDouble(lat))
                });

                /* map.MoveToRegion(
                *  MapSpan.FromCenterAndRadius(
                *  new Position(Convert.ToDouble(lat), Convert.ToDouble(lon)), Distance.FromMiles(0.2)));
                *  map.UiSettings.ZoomControlsEnabled = false;
                *  var pos = new Position(Convert.ToDouble(lat), Convert.ToDouble(lon));
                *  var pin = new Pin
                *  {
                *    Type = PinType.SearchResult,
                *    Icon = BitmapDescriptorFactory.FromBundle("icon_car.png"),
                *    Position = pos,
                *    Label = "Atual Local",
                *    Address = "custom detail info"
                *  };
                *  map.Pins.Add(pin);*/
            }
            catch (Exception ex)
            {
                GetPosition();
                Thread.Sleep(2000);
            }
        }
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            // add item to map
            CLLocationCoordinate2D coord = MapItems[indexPath.Row].Placemark.Location.Coordinate;

            map.AddAnnotations(new MKPointAnnotation()
            {
                Title      = MapItems[indexPath.Row].Name,
                Coordinate = coord
            });

            map.SetCenterCoordinate(coord, true);

            //Also POST this item to the RecentHistory API
            HistoryItem item = new HistoryItem()
            {
                Id           = "0",
                Name         = MapItems[indexPath.Row].Name,
                DateOfSearch = DateTime.Now.ToString("F"),
                Latitude     = coord.Latitude.ToString(),
                Longitude    = coord.Longitude.ToString()
            };

            /*string test = DateTime.Now.ToLongDateString();
             * test = DateTime.Now.ToLongTimeString();
             * test = DateTime.Now.ToShortDateString();
             * test = DateTime.Now.ToShortTimeString();
             * test = DateTime.Now.ToString();
             * test = DateTime.Now.ToString("f0");
             * test = DateTime.Now.ToString("F");*/

            _mainViewModel.PostHistoryItem(item);

            //Back to main view
            DismissViewController(false, null);
        }
 public override void AddClusters(CKCluster[] clusters)
 {
     _internalMap.AddAnnotations(clusters);
 }
示例#16
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var navController = new UINavigationController();

            navController.NavigationBarHidden = false;

            this.NavigationItem.Title = "MAPA";

            //zobrazeni mapy na obrazovce
            MKMapView mapa = new MKMapView(View.Bounds);

            mapa.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            mapa.ZoomEnabled      = true;
            View.AddSubview(mapa);

            mapa.ShowsScale = true;

            mapa.ShowsPointsOfInterest = true;

            mapa.ShowsCompass = true;

            mapa.ShowsTraffic = true;



            //zobrazeni tlacitka pro polohu uzivatele
            var buttonLokace = MKUserTrackingButton.FromMapView(mapa);

            buttonLokace.Frame = new CGRect(320, 550, 32, 32);
            buttonLokace.Layer.BackgroundColor = UIColor.White.CGColor;
            buttonLokace.Layer.BorderColor     = UIColor.FromRGB(0, 122, 255).CGColor;
            buttonLokace.Layer.BorderWidth     = 1;
            buttonLokace.Layer.CornerRadius    = 5;
            View.AddSubview(buttonLokace);

            //zobrazeni hlasky pro povoleni lokacnich sluzeb a nastaveni lokalizace uzivatele na true
            lokace.RequestWhenInUseAuthorization();

            //zobrazeni uzivatelovy polohy
            mapa.ShowsUserLocation = true;

            //vycentrovani mapy na pozici uzivatele

            /*mapa.DidUpdateUserLocation += (sender, e) =>
             * {
             *  if (mapa.UserLocation != null)
             *  {
             *      CLLocationCoordinate2D souradnice = mapa.UserLocation.Coordinate;
             *      //nastaveni rozsahu zobrazovani mapy
             *      MKCoordinateSpan rozsah = new MKCoordinateSpan(MileNaZemepisnouSirku(0.25), MileNaZemepisnouDelku((0.25), souradnice.Latitude));
             *      mapa.Region = new MKCoordinateRegion(souradnice, rozsah);
             *
             *  }
             * };*/

            //pokud uzivatel nepovoli lokacni sluzby anebo nejsou k dispozici, mapa se vycentruje na Prahu a okoli
            if (!mapa.UserLocationVisible)
            {
                CLLocationCoordinate2D souradnice = new CLLocationCoordinate2D(50.1025011, 14.475905300000022);
                MKCoordinateSpan       rozsah     = new MKCoordinateSpan(MileNaZemepisnouSirku(10), MileNaZemepisnouDelku(10, souradnice.Latitude));
                mapa.Region = new MKCoordinateRegion(souradnice, rozsah);
            }

            //VYHLEDAVANI
            var searchResultsController = new SearchResultsViewController(mapa);
            var searchUpdater           = new SearchResultsUpdator();

            searchUpdater.UpdateSearchResults += searchResultsController.Search;

            searchController = new UISearchController(searchResultsController)
            {
                SearchResultsUpdater = searchUpdater
            };

            searchController.SearchBar.SizeToFit();
            searchController.SearchBar.SearchBarStyle             = UISearchBarStyle.Minimal;
            searchController.SearchBar.Placeholder                = "Vyhledejte váš oblíbený hrad či zámek...";
            searchController.HidesNavigationBarDuringPresentation = false;
            NavigationItem.TitleView   = searchController.SearchBar;
            DefinesPresentationContext = true;

            mapa.GetViewForAnnotation += GetViewForAnnotation;

            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Mělník",
                Coordinate = new CLLocationCoordinate2D(50.3508344, 14.4730828)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Lednice",
                Coordinate = new CLLocationCoordinate2D(48.8016903, 16.8054806)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Kácov",
                Coordinate = new CLLocationCoordinate2D(49.7768931, 15.0282231)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Slavkov",
                Coordinate = new CLLocationCoordinate2D(49.1547997, 16.8745169)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Pernštejn",
                Coordinate = new CLLocationCoordinate2D(49.4509142, 16.3182508)
            });
            mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Žebrák",
                Coordinate = new CLLocationCoordinate2D(49.8868308, 13.8815631)
            }); mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Karlštejn",
                Coordinate = new CLLocationCoordinate2D(49.9391167, 14.1882903)
            }); mapa.AddAnnotations(new MKPointAnnotation()
            {
                Title      = "Křivoklát",
                Coordinate = new CLLocationCoordinate2D(50.0378419, 13.8722575)
            });
            mapa.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Houska",
                Coordinate = new CLLocationCoordinate2D(50.4909178, 14.6240339)
            });
            mapa.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "Točník",
                Coordinate = new CLLocationCoordinate2D(49.8906097, 13.8872011)
            });
        }
        public void DisplayAnnotations(List<IMKAnnotation> annotations, MKMapView mapView)
        {
            List<IMKAnnotation> before = new List<IMKAnnotation>();
            foreach (IMKAnnotation annotation in mapView.Annotations)
                before.Add(annotation);
//            MKUserLocation userLocation = mapView.UserLocation;
//            if (userLocation != null)
//                before.Remove(userLocation);
            List<IMKAnnotation> after = new List<IMKAnnotation>(annotations);
            List<IMKAnnotation> toKeep = new List<IMKAnnotation>(before);
            toKeep = FBUtils.Intersect(toKeep, after);
            List<IMKAnnotation> toAdd = new List<IMKAnnotation>(after);
            toAdd.RemoveAll((IMKAnnotation obj) =>
                {
                    return toKeep.Contains(obj);
                });
            List<IMKAnnotation> toRemove = new List<IMKAnnotation>(before);
            toRemove.RemoveAll((IMKAnnotation obj) =>
                {
                    return after.Contains(obj);
                });

            NSOperationQueue.MainQueue.AddOperation(delegate ()
                {
                    mapView.AddAnnotations(toAdd.ToArray());
                    mapView.RemoveAnnotations(toRemove.ToArray());
                }
            );

        }