Exemplo n.º 1
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();
            }
        }
Exemplo n.º 2
0
 public static Binding3DLocation ToBinding3DLocation(this MKUserLocation loc)
 => new Binding3DLocation(
     loc.Location.Altitude,
     loc.Coordinate.Latitude,
     loc.Coordinate.Longitude,
     loc.Location.HorizontalAccuracy,
     loc.Location.VerticalAccuracy,
     loc.Location.Speed);
Exemplo n.º 3
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));
        }
 public void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (!isZoomedIn)
     {
         var mapRegion = new MKCoordinateRegion(mapView.UserLocation.Coordinate, new MKCoordinateSpan(0.001, 0.001));
         mapView.SetRegion(mapRegion, true);
         isZoomedIn = true;
     }
 }
Exemplo n.º 5
0
 /// <summary>
 /// Center the map when the user is located
 /// </summary>
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (userLocation != null)
     {
         var span   = new MKCoordinateSpan(15, 15);
         var region = new MKCoordinateRegion(userLocation.Coordinate, span);
         mapView.SetRegion(region, true);
     }
 }
Exemplo n.º 6
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (mapView.UserLocation != null)
     {
         CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
         MKCoordinateSpan       span   = new MKCoordinateSpan(0.1, 0.1);
         mapView.Region = new MKCoordinateRegion(coords, span);
     }
 }
Exemplo n.º 7
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (mapView.UserLocation != null)
     {
         MapDelegate.color = 2;
         CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
         MKCoordinateSpan       span   = new MKCoordinateSpan(MilesToLatitudeDegrees(1), MilesToLongitudeDegrees(1, coords.Latitude));
         mapView.Region = new MKCoordinateRegion(coords, span);
     }
 }
Exemplo n.º 8
0
 public void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     Console.WriteLine("Weak Lat: {0}, Long: {1}, Alt: {2}", userLocation.Coordinate.Latitude, userLocation.Coordinate.Longitude, userLocation.Location.Altitude);
     currLocation = userLocation.Coordinate;
     if (firstLaunch) {
         mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true);
         firstLaunch = false;
     }
     else
         mapView.SetCenterCoordinate(currLocation, true);
 }
Exemplo n.º 9
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (userLocation != null && !m_HasZoomedToUser)
     {
         CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
         MKCoordinateSpan       span   = new MKCoordinateSpan(GeoConverter.MilesToLatitudeDegrees(MapSettings.ScreenMapSpan),
                                                              GeoConverter.MilesToLongitudeDegrees(MapSettings.ScreenMapSpan, coords.Latitude));
         mapView.Region    = new MKCoordinateRegion(coords, span);
         m_HasZoomedToUser = true;
     }
 }
Exemplo n.º 10
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     if (!_locationSet) {
         _locationSet = true;
         ZoomToUserLocation (mapView, userLocation);
     }
     else
     {
         mapView.SetCenterCoordinate(userLocation.Coordinate, true);
     }
 }
Exemplo n.º 11
0
        public void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
        {
            if (userLocation != null)
            {
                Console.WriteLine("location: " + userLocation.Coordinate.Latitude + " " + userLocation.Coordinate.Longitude);

                if (!ViewModel.IsNavigating || !ViewModel.HasStaredNavigation)
                {
                    return;
                }

                if (currentStepIndex < ViewModel.Routes.Count - 1)
                {
                    RouteItem  nextItem    = ViewModel.Routes [currentStepIndex + 1];
                    CLLocation nexLocation = new CLLocation(nextItem.Lat, nextItem.Long);

                    double distanceToNext = userLocation.Location.DistanceFrom(nexLocation);

                    Console.WriteLine("distance to next steps " + distanceToNext);

                    RouteItem  currentItem       = ViewModel.Routes [currentStepIndex];
                    CLLocation currentLocation   = new CLLocation(currentItem.Lat, currentItem.Long);
                    double     distanceToCurrent = userLocation.Location.DistanceFrom(currentLocation);

                    double distanceCurrentToNext = nexLocation.DistanceFrom(currentLocation);

                    if (distanceToNext < distanceCurrentToNext && distanceToCurrent > 5 && distanceToNext < 100)
                    {
                        Console.WriteLine("move to next steps");
                        collectionRoutes.SetContentOffset(new CGPoint(collectionRoutes.Frame.Width * (currentStepIndex + 1), 0), true);
                        DrawStepForIndex(currentStepIndex + 1, false);
                    }
                    else if (currentStepIndex > 0)
                    {
                        RouteItem  prevItem     = ViewModel.Routes [currentStepIndex - 1];
                        CLLocation prevLocation = new CLLocation(prevItem.Lat, prevItem.Long);

                        double distanceToPrev        = userLocation.Location.DistanceFrom(prevLocation);
                        double distancePrevToCurrent = prevLocation.DistanceFrom(currentLocation);

                        if (distanceToPrev < 5 && distanceToCurrent > distancePrevToCurrent)
                        {
                            // user go back to prev step
                            collectionRoutes.SetContentOffset(new CGPoint(collectionRoutes.Frame.Width * (currentStepIndex - 1), 0), true);
                            DrawStepForIndex(currentStepIndex - 1, false);
                        }
                    }
                }
            }
        }
Exemplo n.º 12
0
 public void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     Console.WriteLine("Weak Lat: {0}, Long: {1}, Alt: {2}", userLocation.Coordinate.Latitude, userLocation.Coordinate.Longitude, userLocation.Location.Altitude);
     currLocation = userLocation.Coordinate;
     if (firstLaunch)
     {
         mapView.SetRegion(MKCoordinateRegion.FromDistance(currLocation, 250, 250), true);
         firstLaunch = false;
     }
     else
     {
         mapView.SetCenterCoordinate(currLocation, true);
     }
 }
Exemplo n.º 13
0
        public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
        {
            if (mapView.ShowsUserLocation)
            {
                if (_renderer.RequestedShowUserLocation)
                {
                    _renderer.MoveToRegion(MapRegion.FromPositions(new List <Position> {
                        new Position(userLocation.Coordinate.Latitude,
                                     userLocation.Coordinate.Longitude)
                    }), false);

                    _renderer.ResetShowUserLocation();
                }
            }
        }
            public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view)
            {
                MKUserLocation userLocationAnnotation = view.Annotation as MKUserLocation;

                if (userLocationAnnotation != null)
                {
                    CLLocationCoordinate2D coord  = userLocationAnnotation.Location.Coordinate;
                    MKCoordinateRegion     region = MKCoordinateRegion.FromDistance(coord, 500, 500);

                    mapView.CenterCoordinate = coord;
                    mapView.Region           = region;

                    userLocationAnnotation.Title = "I am here";
                }
            }
Exemplo n.º 15
0
        void ZoomToUserLocation(MKMapView mapView, MKUserLocation l)
        {
            var span = new MKCoordinateSpan
            {
                LatitudeDelta = 0.1,
                LongitudeDelta = 0.1,
            };

            var region = new MKCoordinateRegion
            {
                Center = l.Coordinate,
                Span = span,
            };

            mapView.SetRegion (region, true);
        }
Exemplo n.º 16
0
        public sealed override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
        {
            var coordinate = userLocation.ToBinding3DLocation();

            if (mapView is BindingMKMapView v)
            {
                v.UserCurrentLocation = coordinate;
            }
            if (LocationChanged != null)
            {
                if (LocationChanged.CanExecute(coordinate))
                {
                    LocationChanged.Execute(coordinate);
                }
            }
        }
        private MKAnnotationView GetViewForUserAnnotation(MKMapView mapView, MKUserLocation annotation)
        {
            ////const string AnnotationId = "userAnnotation";
            ////var annotationView = mapView.DequeueReusableAnnotation(AnnotationId) as MKPinAnnotationView;
            ////if (annotationView == null)
            ////{
            ////    annotationView = new MKPinAnnotationView(annotation, AnnotationId);
            ////}

            ////annotationView.PinColor = MKPinAnnotationColor.Green;
            ////annotationView.CanShowCallout = true;
            ////annotationView.Draggable = true;
            ////annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);

            ////return annotationView;
            return(null);
        }
Exemplo n.º 18
0
        public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
        {
            if (mapView.UserLocation != null)
            {
                CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
                MKCoordinateSpan       span   = new MKCoordinateSpan(MilesToLatitudeDegrees(1), MilesToLongitudeDegrees(1, coords.Latitude));
                mapView.Region = new MKCoordinateRegion(coords, span);


                mapView.AddAnnotation(new MKPointAnnotation()
                {
                    Title      = "Victim 5",
                    Subtitle   = "1 510 555-5555 - Rescue in progress",
                    Coordinate = new CLLocationCoordinate2D(37.777257, -122.391061)
                });
            }
        }
Exemplo n.º 19
0
            /// <summary>
            /// Callback for when the user's location is found, we want to zoom in when this happens
            /// </summary>
            public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
            {
                var placemark = mapView.Annotations.OfType <MKPlacemark>().FirstOrDefault();

                if (placemark != null && userLocation.Location != null)
                {
                    //Calculate the mid point between 2 locations
                    double latitude = Math.Min(userLocation.Coordinate.Latitude, placemark.Coordinate.Latitude) +
                                      Math.Abs(userLocation.Coordinate.Latitude - placemark.Coordinate.Latitude) / 2;
                    double longitude = Math.Min(userLocation.Coordinate.Longitude, placemark.Coordinate.Longitude) +
                                       Math.Abs(userLocation.Coordinate.Longitude - placemark.Coordinate.Longitude) / 2;
                    var midPoint = new CLLocationCoordinate2D(latitude, longitude);

                    //Display the distance between the points (and multiple by 1.05 to get space on the edges)
                    var distance = userLocation.Location.DistanceFrom(placemark.Location) * 1.05;
                    var region   = MKCoordinateRegion.FromDistance(midPoint, distance, distance);

                    mapView.SetRegion(region, true);
                }
            }
Exemplo n.º 20
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();
            }
        }
Exemplo n.º 21
0
		public override void DidUpdateUserLocation (MKMapView mapView, MKUserLocation userLocation)
		{
			if (OnUpdateUserLocation != null)
				OnUpdateUserLocation(userLocation);
		}
			/// <summary>
			/// Center the map when the user is located
			/// </summary>
			public override void DidUpdateUserLocation (MKMapView mapView, MKUserLocation userLocation)
			{
				if (userLocation != null) {
					var span = new MKCoordinateSpan (15, 15);
					var region = new MKCoordinateRegion (userLocation.Coordinate, span);
					mapView.SetRegion (region, true);
				}
			}
Exemplo n.º 23
0
		public override void DidUpdateUserLocation (MKMapView mapView, MKUserLocation userLocation)
		{
			Console.WriteLine("DidUpdateUserLocation");
			// TODO: Implement - see: http://go-mono.com/docs/index.aspx?link=T%3aMonoTouch.Foundation.ModelAttribute
		}
			public override void DidUpdateUserLocation (MKMapView mapView, MKUserLocation userLocation)
			{
				if (mapView.UserLocation != null && parent.shouldCenterOnLocation) {
					CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate;
					MKCoordinateSpan span = new MKCoordinateSpan(MapHelper.MilesToLatitudeDegrees(0.2), MapHelper.MilesToLongitudeDegrees(0.2, coords.Latitude));
					mapView.Region = new MKCoordinateRegion(coords, span);
					parent.shouldCenterOnLocation = false;
				}
			}
Exemplo n.º 25
0
            /// <summary>
            /// Callback for when the user's location is found, we want to zoom in when this happens
            /// </summary>
            public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
            {
                var placemark = mapView.Annotations.OfType<MKPlacemark>().FirstOrDefault ();
                if (placemark != null && userLocation.Location != null) {
                    //Calculate the mid point between 2 locations
                    double latitude = Math.Min (userLocation.Coordinate.Latitude, placemark.Coordinate.Latitude) +
                        Math.Abs (userLocation.Coordinate.Latitude - placemark.Coordinate.Latitude) / 2;
                    double longitude = Math.Min (userLocation.Coordinate.Longitude, placemark.Coordinate.Longitude) +
                        Math.Abs (userLocation.Coordinate.Longitude - placemark.Coordinate.Longitude) / 2;
                    var midPoint = new CLLocationCoordinate2D(latitude, longitude);

                    //Display the distance between the points (and multiple by 1.05 to get space on the edges)
                    var distance = userLocation.Location.DistanceFrom (placemark.Location) * 1.05;
                    var region = MKCoordinateRegion.FromDistance (midPoint, distance, distance);

                    mapView.SetRegion (region, true);
                }
            }
Exemplo n.º 26
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     //base.DidUpdateUserLocation(mapView, userLocation);
 }
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     mapView.SetRegion(new MKCoordinateRegion(userLocation.Coordinate, new MKCoordinateSpan(0.1, 0.1)), true);
 }
Exemplo n.º 28
0
 public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation)
 {
     Debug.WriteLine("DidUpdateUserLocation");
 }