Esempio n. 1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "Victims";


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

            if (CLLocationManager.LocationServicesEnabled)
            {
                mapView.ShowsUserLocation = true;

                locationManager.StartMonitoringSignificantLocationChanges();
                locationManager.StartUpdatingLocation();
            }

            MapDelegate1.color = 2;

            // create our location and zoom for los angeles
            var rcoords = new CLLocationCoordinate2D(37.774628, -122.387341);             // paris
            var span    = new MKCoordinateSpan(MilesToLatitudeDegrees(0.7), MilesToLongitudeDegrees(0.7, rcoords.Latitude));

            // set the coords and zoom on the map
            mapView.Region = new MKCoordinateRegion(rcoords, span);



            PersonDataService persons = new PersonDataService();

            foreach (var person in persons.GetAllPerson())
            {
                mapView.AddAnnotation(new MKPointAnnotation()
                {
                    Title      = person.Name,
                    Subtitle   = person.PhoneNumber + " - Help Me",
                    Coordinate = new CLLocationCoordinate2D(person.latitude, person.longitude)
                });
            }


            // assign the delegate, which handles annotation layout and clicking
            mapView.Delegate = new MapDelegate2(this);



            // add a basic annotation
            var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(37.774628, -122.387341), "Sathish Kumar Natarajan", "415 533 1764");

            mapView.AddAnnotation(annotation);

            btnBack.TouchUpInside += (sender, e) =>
            {
                this.DismissViewController(true, null);
            };
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
        }
        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            var firstViewModel = (FirstViewModel) ViewModel;
            var helenAnnotation = new ZombieAnnotation(firstViewModel.Helen);
            var keithAnnotation = new ZombieAnnotation(firstViewModel.Keith);

            mapView.AddAnnotation(helenAnnotation);
            mapView.AddAnnotation(keithAnnotation);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(firstViewModel.Helen.Location.Lat, firstViewModel.Helen.Location.Lng),
                20000,
                20000), true);

            var button = new UIButton(UIButtonType.RoundedRect);
            button.Frame = new RectangleF(10, 10, 300, 40);
            button.SetTitle("move", UIControlState.Normal);
            Add(button);

            var set = this.CreateBindingSet<FirstView, Core.ViewModels.FirstViewModel>();
            set.Bind(button).To(vm => vm.MoveCommand);
            set.Bind(helenAnnotation).For(a => a.Location).To(vm => vm.Helen.Location);
            set.Bind(keithAnnotation).For(a => a.Location).To(vm => vm.Keith.Location);
            set.Apply();
        }
Esempio n. 5
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;
        }
Esempio n. 6
0
        public void updateTrackLocation()
        {
            try {
                // no gps update yet(not on screen), -180, -180
                if (_mapView.UserLocation.Coordinate.Latitude != -180 && _mapView.UserLocation.Coordinate.Longitude != -180)
                {
                    if (_trackCoordinate.IsValid())
                    {
                        if (_trackPoint == null)
                        {
                            _trackPoint = new PointAnnotation(_trackCoordinate, "Contact", "Here");
                            _mapView.AddAnnotation(_trackPoint);
                        }

                        _userLocation = _mapView.UserLocation.Coordinate;

                        if (_userLocation.IsValid() && RouteLine != null)
                        {
                            _userLocation         = _mapView.UserLocation.Coordinate;
                            RouteLine.Points[0].X = _userLocation.Latitude;
                            RouteLine.Points[0].Y = _userLocation.Longitude;
                            RouteLine.Points[1].X = _trackCoordinate.Latitude;
                            RouteLine.Points[1].Y = _trackCoordinate.Longitude;

                            _trackPoint.Coordinate = _trackCoordinate;
                            _mapView.AddAnnotation(_trackPoint);
                            //put in line here
                            //_mapView.AddOverlay(RouteLine);

                            ZoomIn();
                        }
                        else
                        {
                            throw new Exception("_UserLocation is null");
                        }

                        //calc dist
                        if (_mapView.UserLocation != null)
                        {
                            CLLocation location = new CLLocation(_trackCoordinate.Latitude, _trackCoordinate.Longitude);
                            var        distance = Math.Round(_mapView.UserLocation.Location.Distancefrom(location), 2);
                            if (distance > 9000)
                            {
                                _distanceLbl.Text = "> 9000";
                            }
                            else
                            {
                                _distanceLbl.Text = distance.ToString();
                            }
                        }
                    }
                    ServiceHelper.instance.releaseSemaphore();
                }
            } catch (Exception e) {
                MessageHelper.showErrorMesage("Problem in updateTrackLocation " + e.Message);
            }
        }
Esempio n. 7
0
        protected override void OnElementChanged(ElementChangedEventArgs <View> e)
        {
            base.OnElementChanged(e);
            if (isLoaded)
            {
                nativeMap.RemoveOverlays(nativeMap.Overlays);
            }

            if (e.NewElement == null)
            {
                return;
            }
            if (e.OldElement != null)
            {
                nativeMap = Control as MKMapView;
            }
            element            = Element as ExtendedMap;
            mapDelegate        = new MapDelegate();
            nativeMap          = Control as MKMapView;
            nativeMap.Delegate = null;
            nativeMap.Delegate = mapDelegate;

            var formsMap = (ExtendedMap)e.NewElement;

            CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[element.RouteCoordinates.Count];

            int    index     = 0;
            int    idCounter = 1;
            string icon      = "";

            icon = element.ImageSource;
            foreach (var circle in element.Circles)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius);
                nativeMap.AddOverlay(circleOverlay);
            }

            foreach (var position in element.RouteCoordinates)
            {
                var annot = new CustomAnnotation(new CLLocationCoordinate2D(position.Latitude, position.Longitude), element.CustomPins.FirstOrDefault().Label, "", false, icon);
                annot.Id = idCounter++;
                nativeMap.AddAnnotation(annot);
                //pinCollection.Add(annot.Id, item);
                annotations.Add(annot);
                coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude);
                index++;
            }
            var routeOverlay = MKPolyline.FromCoordinates(coords);

            nativeMap.AddOverlay(routeOverlay);
        }
Esempio n. 8
0
        public override void AddUser()
        {
            _userAnnotation = new UserAnnotation(new CLLocationCoordinate2D
            {
                Latitude  = Settings.UserLatitude,
                Longitude = Settings.UserLongitude
            });

            _nativeMap.AddAnnotation(_userAnnotation);
        }
Esempio n. 9
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            RouteViews = new Dictionary <string, CSRouteView>();

            // load the points from local resource (file)
            var filePath     = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp", "");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List <CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var        latLonArr       = ps.Split(',');
                double     latitude        = Convert.ToDouble(latLonArr[0]);
                double     longitude       = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView       = new MKMapView();
            _mapView.Frame = new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);


            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);

            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation(points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation(annotation);

            annotation = new CSMapAnnotation(points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation(annotation);

            //TODO:create the image annotation

            _mapView.SetRegion(routeAnnotation.Region, false);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            RouteViews = new Dictionary<string,CSRouteView>();

            // load the points from local resource (file)
            var filePath = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp","");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List<CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var latLonArr = ps.Split(',');
                double latitude = Convert.ToDouble(latLonArr[0]);
                double longitude = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView = new MKMapView();
            _mapView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);

            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);
            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation (points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation (annotation);

            annotation = new CSMapAnnotation (points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation (annotation);

            //TODO:create the image annotation

            _mapView.SetRegion (routeAnnotation.Region, false);
        }
Esempio n. 11
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Map = new MKMapView(View.Bounds)
            {
                RotateEnabled = true,
                ScrollEnabled = true,
                ZoomEnabled   = true,
                Delegate      = new MapDelegate(),
                MapType       = MKMapType.Standard
            };

            View.AddSubview(Map);

            foreach (var location in SampleData.Locations)
            {
                Map.AddOverlay(MKPolygon.FromCoordinates(location.BoundaryData
                                                         .Select(boundaryLocation => new CLLocationCoordinate2D(boundaryLocation.Latitude, boundaryLocation.Longitude))
                                                         .ToArray()));

                Map.AddAnnotation(new MKPointAnnotation
                {
                    Title      = location.Title,
                    Coordinate = new CLLocationCoordinate2D(location.Latitude, location.Longitude)
                });
            }

            Map.ShowAnnotations(Map.Annotations, true);
        }
Esempio n. 12
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            try{
                this.Title = "Ubicación de la tienda";

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

                //Mostramos la ubicacion del usuario.
                mapView.ShowsUserLocation = true;
                MKUserLocation usr = mapView.UserLocation;
                usr.Title = "Tú estas aqui";

                var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(Double.Parse(tienda.tienda_latitud), Double.Parse(tienda.tienda_longitud)), tienda.tienda_nombre, tienda.tienda_direccion);
                mapView.AddAnnotation(annotation);

                // establecemos la region a mostrar, poniendo a Chihuahua como region
                var coords = new CLLocationCoordinate2D(28.6352778, -106.08888890000003);                 // Chihuahua
                var span   = new MKCoordinateSpan(MilesToLatitudeDegrees(10), MilesToLongitudeDegrees(10, coords.Latitude));

                // se establece la region.
                mapView.Region = new MKCoordinateRegion(coords, span);

                //Mostrar los diferentes tipos de mapas
                int typesWidth = 260, typesHeight = 30, distanceFromBottom = 60;
                mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight));
                mapTypes.InsertSegment("Mapa", 0, false);
                mapTypes.InsertSegment("Satelite", 1, false);
                mapTypes.InsertSegment("Ambos", 2, false);
                mapTypes.SelectedSegment  = 0;                // Road is the default
                mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
                mapTypes.ValueChanged    += (s, e) => {
                    switch (mapTypes.SelectedSegment)
                    {
                    case 0:
                        mapView.MapType = MKMapType.Standard;
                        break;

                    case 1:
                        mapView.MapType = MKMapType.Satellite;
                        break;

                    case 2:
                        mapView.MapType = MKMapType.Hybrid;
                        break;
                    }
                };
                View.AddSubview(mapTypes);
            } catch (Exception e) {
                Console.WriteLine(e.ToString());
                UIAlertView alert = new UIAlertView()
                {
                    Title = "Ups =(", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo."
                };
                alert.AddButton("Aceptar");
                alert.Show();
            }
        }
Esempio n. 13
0
        private void InitializeMap()
        {
            locationManager = new CLLocationManager();

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

            map = new MKMapView(UIScreen.MainScreen.Bounds);
            View.Add(map);

            if (CLLocationManager.LocationServicesEnabled)
            {
                map.ShowsUserLocation = true;
            }

            var centersForDiseaseControlAnnotation = new MKPointAnnotation {
                Coordinate = new CLLocationCoordinate2D(CDC.Latitude, CDC.Longitude),
                Title      = "Centers for Disease Control",
                Subtitle   = "Zombie Outbreak"
            };

            map.AddAnnotation(centersForDiseaseControlAnnotation);
            Helpers.CenterOnAtlanta(map);
        }
Esempio n. 14
0
        private void PinSavedLocations(MKMapView map)
        {
            var    MapItems        = new List <SavedLocation>();
            var    documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
            string pathToDatabase  = Path.Combine(documentsFolder, "locations_db.db");

            using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
            {
                var query = connection.Table <SavedLocation>();

                foreach (SavedLocation mapItem in query)
                {
                    MapItems.Add(mapItem);
                }
            }
            var userLocations = UserManager.GetUserLocations();

            foreach (SavedLocation item in MapItems)
            {
                CLLocationCoordinate2D coord = new CLLocationCoordinate2D()
                {
                    Longitude = item.Longitude,
                    Latitude  = item.Latitude
                };
                var userCount  = getUserCount(coord, userLocations);
                var customItem = new CustomAnnotation(item.Name, coord, userCount);
                map.AddAnnotation(customItem);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// Load the map data from the properties retreived
        /// </summary>
        private void LoadMapData()
        {
            // value to determin where to zoom in
            var topLeft     = new CLLocationCoordinate2D(-90, 180);
            var bottomRight = new CLLocationCoordinate2D(90, -180);

            // loop through all the properties and add them to the list
            foreach (var item in Properties)
            {
                // create the pin and add the annoation
                var pin = new HeritagePropertyAnnotation(item);
                _mapView.AddAnnotation(pin);

                // determin the topleft and right
                topLeft.Longitude     = Math.Min(topLeft.Longitude, pin.Coordinate.Longitude);
                topLeft.Latitude      = Math.Max(topLeft.Latitude, pin.Coordinate.Latitude);
                bottomRight.Longitude = Math.Max(bottomRight.Longitude, pin.Coordinate.Longitude);
                bottomRight.Latitude  = Math.Min(bottomRight.Latitude, pin.Coordinate.Latitude);
            }

            // zoom in on the annotations
            var region = new MKCoordinateRegion();

            region.Center = new CLLocationCoordinate2D(
                topLeft.Latitude - (topLeft.Latitude - bottomRight.Latitude) * 0.5,
                topLeft.Longitude + (bottomRight.Longitude - topLeft.Longitude) * 0.5);
            region.Span.LatitudeDelta  = Math.Abs(topLeft.Latitude - bottomRight.Latitude) * 1.1;
            region.Span.LongitudeDelta = Math.Abs(bottomRight.Longitude - topLeft.Longitude) * 1.1;

            // set the region
            region = _mapView.RegionThatFits(region);
            _mapView.SetRegion(region, true);
        }
Esempio n. 16
0
        protected virtual void AddAnnotationFor(object item)
        {
            var annotation = CreateAnnotation(item);

            _annotations[item] = annotation;
            _mapView.AddAnnotation(annotation);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            _map.MapType           = MKMapType.Standard;
            _map.ShowsUserLocation = true;
            _map.ZoomEnabled       = true;
            _map.ScrollEnabled     = true;

            var mapCenter = new CLLocationCoordinate2D(Tweet.GpsCoordinates.Latitude, Tweet.GpsCoordinates.Longitude);
            var mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 200, 00);

            _map.CenterCoordinate = mapCenter;
            _map.Region           = mapRegion;

            _delegate     = new MapDelegate();
            _map.Delegate = _delegate;

            var mkPointAnnotation = new MKPointAnnotation
            {
                Title    = Tweet.User,
                Subtitle = Tweet.Text
            };

            mkPointAnnotation.SetCoordinate(new CLLocationCoordinate2D(Tweet.GpsCoordinates.Latitude, Tweet.GpsCoordinates.Longitude));
            _map.AddAnnotation(mkPointAnnotation);
        }
Esempio n. 18
0
        public MapController(Entity entity)
        {
            try {
                Entity = entity;

                Title = Entity.EntityTypeName;

                _map = new MKMapView ();

                _pin = new Pin(Entity);

                _map.Frame = View.Bounds;
                _map.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

                _map.AddAnnotation(_pin);

                _map.Region = new MKCoordinateRegion (_pin.Coordinate, new MKCoordinateSpan (0.01, 0.01));

                View.AddSubview (_map);

                _map.SelectAnnotation(_pin, true);

            } catch (Exception error) {
                Log.Error (error);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
			
            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);
            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
			if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
				locationManager.RequestAlwaysAuthorization ();
			}
            map.ShowsUserLocation = true;

            // TODO: Step 3d - specify a custom map delegate
//            var mapDelegate = new MyMapDelegate();
//            map.Delegate = mapDelegate;

            // Add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title = "MyAnnotation",
                Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // TODO: Step 3f - add a custom annotation
//            map.AddAnnotation(new CustomAnnotation("CustomSpot", new MonoTouch.CoreLocation.CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 3a - remove old GetViewForAnnotation delegate code to new delegate - we will recreate this next
            // Customize annotation view via GetViewForAnnotation delegate
            map.GetViewForAnnotation = delegate(MKMapView mapView, NSObject annotation)
            {
                if (annotation is MKUserLocation)
                    return null;

                MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId);
                if (pinView == null)
                {
                    pinView = new MKPinAnnotationView(annotation, pId);

                    pinView.PinColor = MKPinAnnotationColor.Green;
                    pinView.CanShowCallout = true;

                    // Add accessory views to the pin
                    pinView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
					pinView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("Icon-29.png"));
                }

                return pinView;
            };
        }
        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();
            mapView.Delegate = new MyDelegate();
            View = mapView;

            base.ViewDidLoad();

            // ios7 layout
            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
                EdgesForExtendedLayout = UIRectEdge.None;

            var secondViewModel = (SecondViewModel)ViewModel;
            var hanAnnotation = new ZombieAnnotation(secondViewModel.Han);

            mapView.AddAnnotation(hanAnnotation);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                new CLLocationCoordinate2D(secondViewModel.Han.Location.Lat, secondViewModel.Han.Location.Lng),
                20000,
                20000), true);

            var button = new UIButton(UIButtonType.RoundedRect);
            button.Frame = new RectangleF(10, 10, 300, 40);
            button.SetTitle("move", UIControlState.Normal);
            Add(button);

            var set = this.CreateBindingSet<SecondView, Core.ViewModels.SecondViewModel>();
            set.Bind(hanAnnotation).For(a => a.Location).To(vm => vm.Han.Location);
            set.Bind(button).For("Title").To(vm => vm.Han.Location);
            set.Apply();
        }
		public override void LoadView ()
		{
			// Set title of screen to game title
			Title = Game.Title;

			// Create MapView and add to Container View
			map = new MKMapView (UIScreen.MainScreen.Bounds);
			View = map;

			// Center map on current location
			map.DidUpdateUserLocation += (sender, e) => {
				if (map.UserLocation != null) {
					CLLocationCoordinate2D coords = map.UserLocation.Coordinate;
					MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));
					map.Region = new MKCoordinateRegion(coords, span);
				}
			};

			map.ShowsUserLocation = true;
			map.ZoomEnabled = true;
			map.ShowsPointsOfInterest = false;

			// Add Stockists to map
			Game.Stockists.ForEach (shop => map.AddAnnotation (new MKPointAnnotation () {
				Title = shop.Title,
				Coordinate = new CLLocationCoordinate2D () {
					Latitude = shop.Latitude,
					Longitude = shop.Longitude
				}
			}));
		}
        public MapController(Entity entity)
        {
            try {
                Entity = entity;

                Title = Entity.EntityTypeName;

                _map = new MKMapView();

                _pin = new Pin(Entity);

                _map.Frame            = View.Bounds;
                _map.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;

                _map.AddAnnotation(_pin);

                _map.Region = new MKCoordinateRegion(_pin.Coordinate, new MKCoordinateSpan(0.01, 0.01));

                View.AddSubview(_map);

                _map.SelectAnnotation(_pin, true);
            } catch (Exception error) {
                Log.Error(error);
            }
        }
Esempio n. 23
0
        public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
        {
            var coordinates = mapView.UserLocation.Coordinate;
            var span        = new MKCoordinateSpan(.015, .015);

            mapView.Region = new MKCoordinateRegion(coordinates, span);
            mapView.AddAnnotation(new PlaceAnnotation(new CampingPlace(), coordinates));
        }
Esempio n. 24
0
            public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
            {
                var destLocAnnotation = new MKPointAnnotation();

                destLocAnnotation.Coordinate = _destination;
                destLocAnnotation.Title      = "目的地";
                _mapView.AddAnnotation(destLocAnnotation);

                _userLocation = new CLLocationCoordinate2D(manager.Location.Coordinate.Latitude, manager.Location.Coordinate.Longitude);
                var userLocAnnotation = new MKPointAnnotation();

                userLocAnnotation.Coordinate = _userLocation;
                userLocAnnotation.Title      = "現在地";
                _mapView.AddAnnotation(userLocAnnotation);

                GetRoute();
                ShowUserAndDestinationOnMap();
            }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);

            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }
            map.ShowsUserLocation = true;

            // TODO: Step 2a - Add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "MyAnnotation",
                Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // TODO: Step 2b - Customize annotation view via GetViewForAnnotation delegate
            map.GetViewForAnnotation = delegate(MKMapView mapView, NSObject annotation)
            {
                if (annotation is MKUserLocation)
                {
                    return(null);
                }

                MKPinAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId);
                if (pinView == null)
                {
                    pinView = new MKPinAnnotationView(annotation, pId);

                    // TODO: Step 2e - Move one-time setup to here
                    pinView.PinColor       = MKPinAnnotationColor.Green;
                    pinView.CanShowCallout = true;

                    // TODO: Step 2d - Add accessory views to the pin
                    pinView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
                    pinView.LeftCalloutAccessoryView  = new UIImageView(UIImage.FromFile("Icon-29.png"));
                }

                return(pinView);
            };
        }
Esempio n. 26
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Title = "MapView Annotation";

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

            // create our location and zoom for los angeles
            var coords = new CLLocationCoordinate2D(48.857, 2.351);             // paris
            var span   = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude));

            // set the coords and zoom on the map
            mapView.Region = new MKCoordinateRegion(coords, span);

            // assign the delegate, which handles annotation layout and clicking
            mapView.Delegate = new MapDelegate(this);

            // add a basic annotation
            var annotation = new BasicMapAnnotation(new CLLocationCoordinate2D(48.857, 2.351), "Paris", "City of Light");

            mapView.AddAnnotation(annotation);


            #region Not related to this sample
            int typesWidth = 260, typesHeight = 30, distanceFromBottom = 60;
            mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight));
            mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight));
            mapTypes.BackgroundColor    = UIColor.White;
            mapTypes.Layer.CornerRadius = 5;
            mapTypes.ClipsToBounds      = true;
            mapTypes.InsertSegment("Road", 0, false);
            mapTypes.InsertSegment("Satellite", 1, false);
            mapTypes.InsertSegment("Hybrid", 2, false);
            mapTypes.SelectedSegment  = 0;            // Road is the default
            mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
            mapTypes.ValueChanged    += (s, e) => {
                switch (mapTypes.SelectedSegment)
                {
                case 0:
                    mapView.MapType = MKMapType.Standard;
                    break;

                case 1:
                    mapView.MapType = MKMapType.Satellite;
                    break;

                case 2:
                    mapView.MapType = MKMapType.Hybrid;
                    break;
                }
            };
            View.AddSubview(mapTypes);
            #endregion
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			try{
				this.Title = "Ubicación de la tienda";

				mapView = new MKMapView(View.Bounds);	
				mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
				View.AddSubview(mapView);
			
				//Mostramos la ubicacion del usuario.
				mapView.ShowsUserLocation = true;
				MKUserLocation usr = mapView.UserLocation;
				usr.Title = "Tú estas aqui";

				var annotation = new BasicMapAnnotation (new CLLocationCoordinate2D (Double.Parse(tienda.tienda_latitud), Double.Parse(tienda.tienda_longitud)), tienda.tienda_nombre,tienda.tienda_direccion);
				mapView.AddAnnotation (annotation);	

				// establecemos la region a mostrar, poniendo a Chihuahua como region
				var coords = new CLLocationCoordinate2D(28.6352778, -106.08888890000003); // Chihuahua
				var span = new MKCoordinateSpan(MilesToLatitudeDegrees (10), MilesToLongitudeDegrees (10, coords.Latitude));

				// se establece la region.
				mapView.Region = new MKCoordinateRegion (coords, span);

				//Mostrar los diferentes tipos de mapas
				int typesWidth=260, typesHeight=30, distanceFromBottom=60;
				mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight));
				mapTypes.InsertSegment("Mapa", 0, false);
				mapTypes.InsertSegment("Satelite", 1, false);
				mapTypes.InsertSegment("Ambos", 2, false);
				mapTypes.SelectedSegment = 0; // Road is the default
				mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
				mapTypes.ValueChanged += (s, e) => {
					switch(mapTypes.SelectedSegment) {
					case 0:
						mapView.MapType = MKMapType.Standard;
						break;
					case 1:
						mapView.MapType = MKMapType.Satellite;
						break;
					case 2:
						mapView.MapType = MKMapType.Hybrid;
						break;
					}
				};
				View.AddSubview(mapTypes);
			} catch(Exception e){
				Console.WriteLine (e.ToString());
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =(", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}
		}
Esempio n. 28
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);

            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }
            map.ShowsUserLocation = true;

            // specify a custom map delegate
            var mapDelegate = new MyMapDelegate();

            map.Delegate = mapDelegate;

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

            // add a custom annotation
            // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 4a - draw a circle overlay
            var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile

            map.AddOverlay(circleOverlay);

            // TODO: Step 4b - draw a polygon (Wyoming)
            var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
            {
                new CLLocationCoordinate2D(45.00, -111.00),
                new CLLocationCoordinate2D(45, -104),
                new CLLocationCoordinate2D(41, -104),
                new CLLocationCoordinate2D(41, -111)
            });

            map.AddOverlay(stateOverlay);
        }
		//TODO : Demo 4 - Step 5 - Plot search results on map
		private void PlotResultsOnMap (MKMapView mapview, List<MKMapItem> items)
		{
			foreach (var item in items) {
				mapview.AddAnnotation (new MKPointAnnotation () {
					Title = item.Name,
					Subtitle = item.PhoneNumber ?? "",
					Coordinate = new CLLocationCoordinate2D (item.Placemark.Location.Coordinate.Latitude, item.Placemark.Location.Coordinate.Longitude)
				});
			}
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);

            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                locationManager.RequestWhenInUseAuthorization();
            }
            map.ShowsUserLocation = true;

            // TODO: Step 3d - specify a custom map delegate
            var mapDelegate = new MyMapDelegate();

            map.Delegate = mapDelegate;

            // Add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title      = "MyAnnotation",
                Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // TODO: Step 3f - add a custom annotation
            map.AddAnnotation(new CustomAnnotation("CustomSpot", new MonoTouch.CoreLocation.CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 3a - remove old GetViewForAnnotation delegate code to new delegate - we will recreate this next
            // [removed]
        }
Esempio n. 31
0
        public void dropPinAtPoint(CGPoint pointToConvert)
        {
            CLLocationCoordinate2D convertedPoint = mainMapView.ConvertPoint(pointToConvert, mainMapView);
            String pinTitle       = String.Format("Pin Number {0}", itemsArray.Count);
            String subCoordinates = String.Format("{0},{1}", convertedPoint.Latitude.ToString(), convertedPoint.Longitude.ToString());

            droppedPin = new MyAnnotation(convertedPoint, pinTitle, subCoordinates);
            mainMapView.AddAnnotation(droppedPin);
            itemsArray.Add(droppedPin);
            updatePolygon();
        }
 // TODO: Step 5b - plot found items
 private void PlotItems(MKMapView mapview, List <MKMapItem> items)
 {
     foreach (var item in items)
     {
         mapview.AddAnnotation(new MKPointAnnotation()
         {
             Title      = item.Name,
             Coordinate = new CLLocationCoordinate2D(item.Placemark.Location.Coordinate.Latitude, item.Placemark.Location.Coordinate.Longitude)
         });
     }
 }
Esempio n. 33
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            UITouch aTouch   = (UITouch)touches.AnyObject;
            PointF  location = aTouch.LocationInView(this);

            var coordinate = _mapView.ConvertPoint(location, this);

            if (this.HasPoint)
            {
                _mapView.RemoveAnnotation(point);
                point = new PointAnnotation(coordinate, "Meeting Place", "Here");
                _mapView.AddAnnotation(point);
            }
            else
            {
                point = new PointAnnotation(coordinate, "Meeting Place", "Here");
                _mapView.AddAnnotation(point);
                this.HasPoint = true;
            }
        }
Esempio n. 34
0
        protected override void AddCustomerToMap(Customer customer)
        {
            var annotation = new CustomerAnnotation(new
                                                    CLLocationCoordinate2D
            {
                Latitude  = customer.Latitude,
                Longitude = customer.Longitude
            },
                                                    customer);

            _nativeMap.AddAnnotation(annotation);
        }
Esempio n. 35
0
        public override void ViewDidLoad()
        {
            var mapView = new MKMapView();

            mapView.Delegate = new MyDelegate();
            View             = mapView;

            base.ViewDidLoad();

            // ios7 layout
            if (RespondsToSelector(new Selector("edgesForExtendedLayout")))
            {
                EdgesForExtendedLayout = UIRectEdge.None;
            }

            var firstViewModel  = (FirstViewModel)ViewModel;
            var helenAnnotation = new ZombieAnnotation(firstViewModel.Helen);
            var keithAnnotation = new ZombieAnnotation(firstViewModel.Keith);

            mapView.AddAnnotation(helenAnnotation);
            mapView.AddAnnotation(keithAnnotation);

            mapView.SetRegion(MKCoordinateRegion.FromDistance(
                                  new CLLocationCoordinate2D(firstViewModel.Helen.Location.Lat, firstViewModel.Helen.Location.Lng),
                                  20000,
                                  20000), true);

            var button = new UIButton(UIButtonType.RoundedRect);

            button.Frame = new RectangleF(10, 10, 300, 40);
            button.SetTitle("move", UIControlState.Normal);
            Add(button);

            var set = this.CreateBindingSet <FirstView, Core.ViewModels.FirstViewModel>();

            set.Bind(button).To(vm => vm.MoveCommand);
            set.Bind(helenAnnotation).For(a => a.Location).To(vm => vm.Helen.Location);
            set.Bind(keithAnnotation).For(a => a.Location).To(vm => vm.Keith.Location);
            set.Apply();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);
            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
			if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
				locationManager.RequestWhenInUseAuthorization();
			}
            map.ShowsUserLocation = true;

            // TODO: Step 3d - specify a custom map delegate
            var mapDelegate = new MyMapDelegate();
            map.Delegate = mapDelegate;

            // Add a point annotation
            map.AddAnnotation(new MKPointAnnotation()
            {
                Title = "MyAnnotation",
                Coordinate = new MonoTouch.CoreLocation.CLLocationCoordinate2D(42.364260, -71.120824)
            });

            // TODO: Step 3f - add a custom annotation
            map.AddAnnotation(new CustomAnnotation("CustomSpot", new MonoTouch.CoreLocation.CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 3a - remove old GetViewForAnnotation delegate code to new delegate - we will recreate this next
            // [removed]
        }
Esempio n. 37
0
        private void UpdatePins()
        {
            Pins = FormsMap.BindablePins;
            NativeMap.RemoveAnnotations(NativeMap.Annotations);

            int i = 0;

            foreach (var pin in Pins)
            {
                var ca = new CustomAnnotation(pin, (++i).ToString(), pin.Type);
                NativeMap.AddAnnotation(ca);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
			
            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);
            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
			if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
				locationManager.RequestAlwaysAuthorization ();
			}
            map.ShowsUserLocation = true;

            // specify a custom map delegate
            var mapDelegate = new MyMapDelegate();
            map.Delegate = mapDelegate;

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

            // add a custom annotation
            // map.AddAnnotation(new CustomAnnotation("CustomSpot", new CLLocationCoordinate2D(38.364260, -68.120824)));

            // TODO: Step 4a - draw a circle overlay
//            var circleOverlay = MKCircle.Circle(new CLLocationCoordinate2D(33.755, -84.39), 100 * 1609.34); // 1609.34 = meters in a mile
//            map.AddOverlay(circleOverlay);

            // TODO: Step 4b - draw a polygon (Wyoming)
//            var stateOverlay = MKPolygon.FromCoordinates(new CLLocationCoordinate2D[]
//                {
//                    new CLLocationCoordinate2D(45.00, -111.00),
//                    new CLLocationCoordinate2D(45, -104),
//                    new CLLocationCoordinate2D(41, -104),
//                    new CLLocationCoordinate2D(41, -111)
//                });
//            map.AddOverlay(stateOverlay);
        }
        protected override void AddPushpinToMap(CustomPin pin)
        {
            try
            {
                var annotation = new CustomPinAnnotation(new
                                                         CLLocationCoordinate2D
                {
                    Latitude  = pin.Latitude,
                    Longitude = pin.Longitude
                },
                                                         pin);

                _nativeMap.AddAnnotation(annotation);

                if (annotation.CustomPin.Duration.HasValue)
                {
                    ShowPushpinInformationPanel(annotation.CustomPin);
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 40
0
            public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
            {
                searchController.SetActive(false, true);

                // add item to map
                CLLocationCoordinate2D coord = MapItems [indexPath.Row].Placemark.Location.Coordinate;

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

                map.SetCenterCoordinate(coord, true);
            }
Esempio n. 41
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            Title = "MapView Annotation";

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

            // create our location and zoom for los angeles
            var coords = new CLLocationCoordinate2D(48.857, 2.351); // paris
            var span = new MKCoordinateSpan(MilesToLatitudeDegrees (2), MilesToLongitudeDegrees (2, coords.Latitude));

            // set the coords and zoom on the map
            mapView.Region = new MKCoordinateRegion (coords, span);

            // assign the delegate, which handles annotation layout and clicking
            mapView.Delegate = new MapDelegate();

            // add a basic annotation
            var annotation = new BasicMapAnnotation (new CLLocationCoordinate2D (48.857, 2.351), "Paris", "City of Light");
            mapView.AddAnnotation (annotation);

            #region Not related to this sample
            int typesWidth=260, typesHeight=30, distanceFromBottom=60;
            mapTypes = new UISegmentedControl(new RectangleF((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight));
            mapTypes.InsertSegment("Road", 0, false);
            mapTypes.InsertSegment("Satellite", 1, false);
            mapTypes.InsertSegment("Hybrid", 2, false);
            mapTypes.SelectedSegment = 0; // Road is the default
            mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
            mapTypes.ValueChanged += (s, e) => {
                switch(mapTypes.SelectedSegment) {
                case 0:
                    mapView.MapType = MKMapType.Standard;
                    break;
                case 1:
                    mapView.MapType = MKMapType.Satellite;
                    break;
                case 2:
                    mapView.MapType = MKMapType.Hybrid;
                    break;
                }
            };
            View.AddSubview(mapTypes);
            #endregion
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            // Perform any additional setup after loading the view, typically from a nib.

            // add the map view
            var map = new MKMapView(UIScreen.MainScreen.Bounds);
            View.Add(map);

            // change the map style
            map.MapType = MKMapType.Standard;

            // enable/disable interactions
            // map.ZoomEnabled = false;
            // map.ScrollEnabled = false;

            // show user location
			if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
				locationManager.RequestWhenInUseAuthorization();
			}
            map.ShowsUserLocation = true;

            // specify a custom map delegate
            var mapDelegate = new MyMapDelegate();
            map.Delegate = mapDelegate;

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

            // TODO: Step 5a - search for an address
            SearchForAddress(map);

            // TODO: Step 5c - search for items of interest
            SearchForLocationsNearPosition(map);
        }
Esempio n. 43
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			try{
			mapView = new MKMapView(View.Bounds);	
			mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
			View.AddSubview(mapView);
			
			//Verificar si el dispositivo es un ipad o un iphone para cargar la tabla correspondiente a cada dispositivo
			if(UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone){
				Title= "Tiendas";
				tiendaCercana = new UIBarButtonItem (UIBarButtonSystemItem.Search);
				tiendaCercana.Target = this;
				this.NavigationItem.RightBarButtonItem = tiendaCercana;
			}else {
				Title = "Tiendas registradas";
				//Creamos el boton para buscar la tienda mas cercana.
				tiendaCercana = new UIBarButtonItem();
				tiendaCercana.Style = UIBarButtonItemStyle.Plain;
				tiendaCercana.Target = this;
				tiendaCercana.Title = "Buscar tienda cercana";
				this.NavigationItem.RightBarButtonItem = tiendaCercana;
			}
	
			//inicializacion del manejador de localizacion.
			iPhoneLocationManager = new CLLocationManager ();
			//Establecer la precision del manejador de localizacion.
			iPhoneLocationManager.DesiredAccuracy = CLLocation.AccuracyNearestTenMeters;

			iPhoneLocationManager.LocationsUpdated += (object sender, CLLocationsUpdatedEventArgs e) => {
				newLocation = e.Locations [e.Locations.Length - 1];
			};

		    List<StoresService> tiendas = storesService.All ();

			//mostramos los puntos rojos sobre cada una de las tiendas registradas.
			foreach (StoresService tienda in tiendas) {
					Console.WriteLine(tienda.nombre +" " + tienda.latitud + " "+tienda.longitud);
				double distancia1 = iPhoneLocationManager.Location.DistanceFrom(new CLLocation(Double.Parse(tienda.latitud),Double.Parse(tienda.longitud)))/1000;
				var annotation = new BasicMapAnnotation (new CLLocationCoordinate2D (Double.Parse(tienda.latitud), Double.Parse(tienda.longitud)), ""+tienda.nombre+" ("+Math.Round(distancia1,2)+"km)", ""+tienda.direccion);
				mapView.AddAnnotation (annotation);			
			}

			//Mostramos la ubicacion del usuario.
			mapView.ShowsUserLocation = true;
			MKUserLocation usr = mapView.UserLocation;
			usr.Title = "Tú estas aqui";
			
			// establecemos la region a mostrar, poniendo a Chihuahua como region
			var coords = new CLLocationCoordinate2D(28.6352778, -106.08888890000003); // Chihuahua
			var span = new MKCoordinateSpan(MilesToLatitudeDegrees (10), MilesToLongitudeDegrees (10, coords.Latitude));

			// se establece la region.
			mapView.Region = new MKCoordinateRegion (coords, span);

			//Mostrar los diferentes tipos de mapas
			int typesWidth=260, typesHeight=30, distanceFromBottom=60;
			mapTypes = new UISegmentedControl(new CGRect((View.Bounds.Width-typesWidth)/2, View.Bounds.Height-distanceFromBottom, typesWidth, typesHeight));
			mapTypes.InsertSegment("Mapa", 0, false);
			mapTypes.InsertSegment("Satelite", 1, false);
			mapTypes.InsertSegment("Ambos", 2, false);
			mapTypes.SelectedSegment = 0; // Road is the default
			mapTypes.AutoresizingMask = UIViewAutoresizing.FlexibleTopMargin;
			mapTypes.ValueChanged += (s, e) => {
				switch(mapTypes.SelectedSegment) {
				case 0:
					mapView.MapType = MKMapType.Standard;
					break;
				case 1:
					mapView.MapType = MKMapType.Satellite;
					break;
				case 2:
					mapView.MapType = MKMapType.Hybrid;
					break;
				}
			};
			View.AddSubview(mapTypes);


			//Añadimos el evento para buscar tienda mas cercana.
			tiendaCercana.Clicked += (sender, e) => {
				try{
					StoresService tiendac= nearestStore(newLocation,tiendas);
					double distancia = newLocation.DistanceFrom(new CLLocation(Double.Parse(tiendac.latitud),Double.Parse(tiendac.longitud)))/1000;
					UIAlertView alert = new UIAlertView () { 
							Title = "Tu tienda mas cercana es:", Message = ""+ tiendac.nombre + "\n "+ tiendac.direccion+"\n"+"Distancia: " + Math.Round(distancia,2) +"km"
					};
					alert.AddButton("Aceptar");
					alert.Show ();

					var coords1 = new CLLocationCoordinate2D(Double.Parse(tiendac.latitud), Double.Parse(tiendac.longitud));
					var span1 = new MKCoordinateSpan(MilesToLatitudeDegrees (0.2), MilesToLongitudeDegrees (0.2, coords.Latitude));

					// set the coords and zoom on the map
					mapView.Region = new MKCoordinateRegion (coords1, span1);
				}catch(Exception){
					UIAlertView alert = new UIAlertView () { 
						Title = "Ups =(", Message = "Algo salio mal, por favor intentalo de nuevo."
					};
					alert.AddButton("Aceptar");
					alert.Show ();
				}
			};  

			// Manejamos la actualizacion de la localizacion del dispositivo.
			iPhoneLocationManager.RequestAlwaysAuthorization ();
			if (CLLocationManager.LocationServicesEnabled)
				iPhoneLocationManager.StartUpdatingLocation ();

			} catch(System.Net.WebException){
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =(", Message = "Algo salio mal, verifica tu conexión a internet e intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			} catch(Exception){
				UIAlertView alert = new UIAlertView () { 
					Title = "Ups =(", Message = "Algo salio mal, por favor intentalo de nuevo."
				};
				alert.AddButton("Aceptar");
				alert.Show ();
			}
		}
Esempio n. 44
0
 private void AddBusStopToMap(MKMapView map, BusStop busStop)
 {
     BusStopMapAnnotation annotation = new BusStopMapAnnotation(busStop);
     map.AddAnnotation(annotation);
 }
        private void InitializeMap()
        {
            locationManager = new CLLocationManager ();

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

            map = new MKMapView (UIScreen.MainScreen.Bounds);
            View.Add (map);

            if (CLLocationManager.LocationServicesEnabled) {
                map.ShowsUserLocation = true;
            }

            var centersForDiseaseControlAnnotation = new MKPointAnnotation {
                Coordinate = new CLLocationCoordinate2D (CDC.Latitude, CDC.Longitude),
                Title = "Centers for Disease Control",
                Subtitle = "Zombie Outbreak"
            };
            map.AddAnnotation (centersForDiseaseControlAnnotation);
            Helpers.CenterOnAtlanta (map);
        }
Esempio n. 46
0
		public override void ViewDidLoad () {
			base.ViewDidLoad ();

			toolbar = new UINavigationBar(new CGRect(0,0,View.Frame.Width,toolbarHeight));
			toolbar.SetItems (new UINavigationItem[]{
					new UINavigationItem("Map")
			}, false);
			toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
			toolbar.TintColor = AppDelegate.ColorNavBarTint;

			Title = Constants.MapPinSubtitle; // "Fira de Barcelona";
			TabBarItem.Title = "Map";
			
			// create our location and zoom for los angeles
			CLLocationCoordinate2D coords = new CLLocationCoordinate2D (Constants.MapPinLatitude, Constants.MapPinLongitude);
			MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees (3), MilesToLongitudeDegrees (3, coords.Latitude));
			
			mapView = new MKMapView(new CGRect(0, toolbarHeight, View.Frame.Width, UIScreen.MainScreen.ApplicationFrame.Height - toolbarHeight ));
			mapView.ShowsUserLocation = true;
			mapView.Frame = new CGRect (0, 0, View.Frame.Width, View.Frame.Height);
			mapView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth|UIViewAutoresizing.FlexibleHeight;
			// set the coords and zoom on the map
			mapView.Region = new MKCoordinateRegion (coords, span);

			segmentedControl = new UISegmentedControl();
			segmentedControl.InsertSegment("Map", 0, false);
			segmentedControl.InsertSegment("Satellite", 1, false);
			segmentedControl.InsertSegment("Hybrid", 2, false);
			segmentedControl.SelectedSegment = 0;
			segmentedControl.ControlStyle = UISegmentedControlStyle.Bar;
			segmentedControl.TintColor = UIColor.DarkGray;
			if (AppDelegate.IsPhone) {
				var topOfSegement = View.Frame.Height - 120;
				segmentedControl.Frame = new CGRect(20, topOfSegement, 282, 30);
				//segmentedControl.Frame = new CGRect(20, 340, 282, 30);
			} else {
				// IsPad
				var left = (View.Frame.Width / 2) - (282 / 2);
				segmentedControl.Frame = new CGRect(left, View.Frame.Height - 130, 282, 30);
				segmentedControl.AutoresizingMask = UIViewAutoresizing.FlexibleMargins;
			}
			segmentedControl.ValueChanged += delegate {
				if (segmentedControl.SelectedSegment == 0)
					mapView.MapType = MapKit.MKMapType.Standard;
				else if (segmentedControl.SelectedSegment == 1)
					mapView.MapType = MapKit.MKMapType.Satellite;
				else if (segmentedControl.SelectedSegment == 2)
					mapView.MapType = MapKit.MKMapType.Hybrid;
			};
			
			try {
				// add a basic annotation, got a bug report about these lines of code
				mapView.AddAnnotation (
					new BasicMapAnnotation (coords, Constants.MapPinTitle, Constants.MapPinSubtitle )
				);
			} catch (Exception mapex) {
				ConsoleD.WriteLine ("Not sure if happens " + mapex.Message); 
			}

			View.AddSubview(mapView);
			View.AddSubview(toolbar);
			View.AddSubview(segmentedControl);
		}
Esempio n. 47
0
        public void BuildView()
        {
            if (mapView == null)
            {

                mapView = new MKMapView();
                RectangleF frame = new RectangleF(0,0,320,367);

                mapView.Frame = frame;

                DV = new DistanceView();

                frame = DV.View.Frame;
                //frame.Y = mapView.Frame.Bottom;
                frame.Y = -DV.View.Frame.Height;

                DV.View.Frame = frame;

                DV.TouchUpInside += delegate(object sender, EventArgs e) {

                    RemoveRouteAnnotation();

                    HideDistanceView();
                };

                mapView.RegionWillChange += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = true;
                    }
                };

                mapView.RegionChanged += delegate(object sender, MKMapViewChangeEventArgs e) {
                    if (routeView != null)
                    {
                        routeView.Hidden = false;
                        routeView.RegionChanged();
                    }
                };

                mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) {
                    if (annotation is MKUserLocation) return null;

                    if (annotation is CycleAnnotation)
                    {
                        var mapAnnotation = annotation as CycleAnnotation;
                        if (mapAnnotation == null) return null;

                        MKPinAnnotationView pinView = (MKPinAnnotationView)mapViewForAnnotation.DequeueReusableAnnotation(MapPin);
                        if (pinView == null)
                        {
                            pinView = new MKPinAnnotationView(mapAnnotation, MapPin);
                        } else {
                            pinView.Annotation = annotation;
                        }

                        int valueToCheck = 0;
                        if (CurrentDisplayMode == DisplayMode.Bikes)
                        {
                            valueToCheck = mapAnnotation.Bike.BikesAvailable;
                        } else {
                            valueToCheck = mapAnnotation.Bike.DocksAvailable;
                        }

                        if ((valueToCheck < 5 && valueToCheck != -1)) {
                            if (valueToCheck == 0)
                            {
                                pinView.PinColor = MKPinAnnotationColor.Red;
                            } else {
                                pinView.PinColor = MKPinAnnotationColor.Purple;
                            }
                        } else {
                            pinView.PinColor = MKPinAnnotationColor.Green;
                        }

                        mapAnnotation.PinView = pinView;

                        pinView.CanShowCallout = true;
                        return pinView;
                    }

                    if (annotation is CSRouteAnnotation)
                    {
                        var routeAnnotation = annotation as CSRouteAnnotation;
                        MKAnnotationView annotationView = null;

                        if (annotationView == null)
                        {
                            routeView = new CSRouteView(new RectangleF (0,0, mapView.Frame.Size.Width, mapView.Frame.Size.Height));
                            routeView.Annotation = routeAnnotation;
                            routeView.MapView = mapViewForAnnotation;
                            annotationView = routeView;
                        }

                        return annotationView;
                    }

                    return null;

                };

                List<MKAnnotation> locations = new List<MKAnnotation>();

                double minLon = 200, minLat = 200, maxLon = -200, maxLat = -200;

                foreach(var bike in BikeLocation.AllBikes)
                {
                    if (bike.Location.Longitude < minLon) minLon = bike.Location.Longitude;
                    if (bike.Location.Latitude < minLat) minLat = bike.Location.Latitude;

                    if (bike.Location.Longitude < maxLon) maxLon = bike.Location.Longitude;
                    if (bike.Location.Latitude > maxLat) maxLat = bike.Location.Latitude;

                    locations.Add(new CycleAnnotation(bike));
                }

                if (locations.Count > 0)
                {
                    mapView.AddAnnotation(locations.ToArray());

                    var tl = new CLLocationCoordinate2D(-90, 180);
                    var br = new CLLocationCoordinate2D(90, -180);

                    foreach(MKAnnotation an in mapView.Annotations)
                    {
                        tl.Longitude = Math.Min(tl.Longitude, an.Coordinate.Longitude);
                        tl.Latitude = Math.Max(tl.Latitude, an.Coordinate.Latitude);

                        br.Longitude = Math.Max(br.Longitude, an.Coordinate.Longitude);
                        br.Latitude = Math.Min(br.Latitude, an.Coordinate.Latitude);

                    }

                    var center = new CLLocationCoordinate2D {
                        Latitude = tl.Latitude - (tl.Latitude - br.Latitude) *0.5,
                        Longitude = tl.Longitude - (tl.Longitude - br.Longitude) *0.5
                    };

                    var span = new MKCoordinateSpan
                    {
                        LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) *0.5,
                        LongitudeDelta = Math.Abs(tl.Longitude - br.Longitude) *0.5

                    };

                    MKCoordinateRegion region = new MKCoordinateRegion (center, span );

                    region = mapView.RegionThatFits(region);

                    mapView.SetRegion(region, true);
                }

                mapView.ShowsUserLocation = true;

                View.AddSubview(mapView);
            }
        }
Esempio n. 48
-1
		public override void DidSelectAnnotationView (MKMapView mapView, MKAnnotationView view)
		{
			try
			{
				if (view.Annotation is MyAnnotation)
				{
					var myAnnotation = (MyAnnotation)view.Annotation;
					
					CalloutMapAnnotation calloutAnnotation = myAnnotation.AssociatedCalloutMapAnnotation;
					if (calloutAnnotation == null)
					{
						calloutAnnotation = new CalloutMapAnnotation(myAnnotation.Coordinate, myAnnotation.Title, "");
					}
					else
					{
						calloutAnnotation.Coordinate = myAnnotation.Coordinate;
					}
					
					myAnnotation.AssociatedCalloutMapAnnotation = calloutAnnotation;
					calloutAnnotation.ParentAnnotation = myAnnotation;
				
					mapView.AddAnnotation(calloutAnnotation);
					selectedAnnotationView = view;
				}
			}
			catch (Exception ex)
			{
				Util.LogException("DidSelectAnnotationView", ex);
			}
		}