Exemple #1
0
        public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            this.annotation = annotation;
            MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(pId);
            // Set current location and location of annotation
            CLLocationCoordinate2D currentLocation    = mapView.UserLocation.Coordinate;
            CLLocationCoordinate2D annotationLocation = annotation.Coordinate;



            // We don't want a special annotation for the user location
            if (currentLocation.Latitude == annotationLocation.Latitude && currentLocation.Longitude == annotationLocation.Longitude)
            {
                return(null);
            }

            if (annotationView == null)
            {
                annotationView = new MKPinAnnotationView(annotation, pId);
            }
            else
            {
                annotationView.Annotation = annotation;
            }

            annotationView.CanShowCallout = true;
            (annotationView as MKPinAnnotationView).AnimatesDrop = false;

            var sss = annotation.GetTitle();

            // Set to true if you want to animate the pin dropping
            if (annotation.GetTitle().Contains("HOSPITAL") || annotation.GetTitle().Contains("Coordinación"))
            {
                (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red;
            }
            else if (opcion == 1)
            {
                (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Purple;
            }
            else if (opcion == 2)
            {
                (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Green;
            }

            annotationView.Selected = true;

            // you can add an accessory view, in this case, we'll add a button on the right, and an image on the left
            detailButton = UIButton.FromType(UIButtonType.DetailDisclosure);

            annotationView.RightCalloutAccessoryView = detailButton;

            // Annotation icon may be specified like this, in case you want it.
            // annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("example.png"));

            return(annotationView);
        }
        protected override MKAnnotationView GetViewForAnnotation(
            MKMapView mapView,
            IMKAnnotation annotation)
        {
            if (Runtime.GetNSObject(annotation.Handle) is MKUserLocation)
            {
                return((MKAnnotationView)null);
            }
            MKAnnotationView mapPin = mapView.DequeueReusableAnnotation("defaultPin");

            if (mapPin == null)
            {
                mapPin                = (MKAnnotationView) new MKPinAnnotationView(annotation, "defaultPin");
                mapPin.Annotation     = annotation;
                mapPin.CanShowCallout = false;
                mapPin.Image          = annotation.GetTitle() == "Available"
                    ? UIImage.FromFile("taxi_available.png")
                    : UIImage.FromFile("taxi_unavailable.png");
            }

            this.AttachGestureToPin(mapPin, annotation);
            return(mapPin);
        }
Exemple #3
0
            public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
            {
                MKAnnotationView anView;

                if (annotation is MKUserLocation)
                {
                    return(null);
                }

                if (annotation is CustomAnnotation)
                {
                    // show monkey annotation
                    anView = mapView.DequeueReusableAnnotation(cId);

                    if (anView == null)
                    {
                        anView = new MKAnnotationView(annotation, cId);
                    }

                    UILabel lbl = new UILabel(new CGRect(0, 0, 30, 30))
                    {
                        Text = ((CustomAnnotation)annotation).EnclosedMembers.ToString()
                    };

                    lbl.Layer.MasksToBounds = true;
                    lbl.Layer.CornerRadius  = lbl.Frame.Width / 2;

                    lbl.TextAlignment             = UITextAlignment.Center;
                    lbl.TextColor                 = UIColor.White;
                    lbl.AdjustsFontSizeToFitWidth = true;
                    lbl.BackgroundColor           = UIColor.Blue;

                    anView.Frame = new CGRect()
                    {
                        Width  = 30,
                        Height = 30
                    };
                    anView.Add(lbl);
                    anView.CanShowCallout = true;
                }
                else
                {
                    var documentsFolder = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
                    pathToDatabase = Path.Combine(documentsFolder, "locations_db.db");

                    AddLocation = UIButton.FromType(UIButtonType.ContactAdd);
                    AddLocation.TouchUpInside += (sender, ea) =>
                    {
                        using (var connection = new SQLite.SQLiteConnection(pathToDatabase))
                        {
                            connection.Insert(new SavedLocation()
                            {
                                Name      = annotation.GetTitle(),
                                Latitude  = annotation.Coordinate.Latitude,
                                Longitude = annotation.Coordinate.Longitude
                            });
                            connection.Close();
                        }
                        mapView.RemoveAnnotation(annotation);
                    };

                    // show pin annotation
                    anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId);

                    if (anView == null)
                    {
                        anView = new MKPinAnnotationView(annotation, pId);
                    }

                    ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red;
                    anView.CanShowCallout            = true;
                    anView.RightCalloutAccessoryView = AddLocation;
                }

                return(anView);
            }
Exemple #4
0
        public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation)
        {
            var pinView = mapView.DequeueReusableAnnotation("colorpin") as MKPinAnnotationView;

            if (pinView == null)
            {
                pinView = new MKPinAnnotationView(annotation, "colorpin")
                {
                    CanShowCallout = true,
                };
            }
            else
            {
                pinView.Annotation = annotation;
            }
            var color = MKPinAnnotationColor.Green;

            var place = viewModel.Places.First(p => p.Latitude == annotation.Coordinate.Latitude && p.Longitude == annotation.Coordinate.Longitude && p.Name == annotation.GetTitle());

            if (place.Stars < 3.5)
            {
                color = MKPinAnnotationColor.Red;
            }
            else if (place.Stars < 4.3)
            {
                color = MKPinAnnotationColor.Purple;
            }

            pinView.PinColor = color;

            return(pinView);
        }