public override void ViewDidLoad() { var mapView = new MKMapView(); View = mapView; base.ViewDidLoad(); var firstViewModel = (FourthViewModel)ViewModel; _regionManager = new RegionManager(mapView); var button = new UIButton(UIButtonType.RoundedRect); button.Frame = new RectangleF(10, 10, 300, 40); button.SetTitle("move", UIControlState.Normal); Add(button); var lat = new UITextField(new RectangleF(10, 50, 130, 40)); lat.KeyboardType = UIKeyboardType.DecimalPad; Add(lat); var lng = new UITextField(new RectangleF(160, 50, 130, 40)); lng.KeyboardType = UIKeyboardType.DecimalPad; Add(lng); var set = this.CreateBindingSet<FourthView, Core.ViewModels.FourthViewModel>(); set.Bind(button).To(vm => vm.UpdateCenterCommand); set.Bind(lat).To(vm => vm.Lat); set.Bind(lng).To(vm => vm.Lng); set.Bind(_regionManager).For(r => r.Center).To(vm => vm.Location); set.Apply(); }
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 ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. // TODO: Step 1a - add the map view var map = new MKMapView(UIScreen.MainScreen.Bounds); View.Add(map); // TODO: Step 1b - change the map style map.MapType = MKMapType.Standard; map.MapType = MKMapType.Satellite; map.MapType = MKMapType.Hybrid; // TODO: Step 1c - enable/disable interactions map.ZoomEnabled = false; map.ScrollEnabled = false; // TODO: Step 1d - show user location if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) { locationManager.RequestWhenInUseAuthorization(); } map.ShowsUserLocation = true; }
void CreateMapView() { _mapView = new MKMapView (UIScreen.MainScreen.Bounds); _mapView.ShowsUserLocation = true; _mapView.Delegate = new MapViewDelegate (); View.InsertSubview (_mapView, 0); }
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 override void ViewDidLoad() { mapView = new MKMapView(); RectangleF frame = new RectangleF(0,0,320,360); mapView.Frame = frame; mapView.ShowsUserLocation = true; var myAnnotation = new MyAnnotation(new CLLocationCoordinate2D(0,0), "Home", "is where the heart is"); mapView.AddAnnotationObject(myAnnotation); UIButton detailButton = UIButton.FromType(UIButtonType.DetailDisclosure); mapView.GetViewForAnnotation = delegate(MKMapView mapViewForAnnotation, NSObject annotation) { var anv = mapView.DequeueReusableAnnotation("thislocation"); if (anv == null) { anv = new MKPinAnnotationView(annotation, "thislocation"); detailButton.TouchUpInside += (s, e) => { Console.WriteLine ("Tapped"); }; anv.RightCalloutAccessoryView = detailButton; } else { anv.Annotation = annotation; } anv.CanShowCallout = true; return anv; }; View.AddSubview(mapView); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // try and dequeue the annotation view MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); else // if we did dequeue one for reuse, assign the annotation to it annotationView.Annotation = annotation; // configure our annotation view properties annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; annotationView.Selected = true; Assembly ass = this.GetType ().Assembly; var annotationImage = UIImage.FromBundle((annotation as BasicPinAnnotation).ImageAdress); annotationView.LeftCalloutAccessoryView = new UIImageView( ResizeImage.MaxResizeImage(annotationImage,(float)40,(float)20)); return annotationView; }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; if (annotation is MKUserLocation) return null; var anno = annotation as MKPointAnnotation; var customPin = GetCustomPin(anno); if (customPin == null) { throw new Exception("Custom pin not found"); } annotationView = mapView.DequeueReusableAnnotation(customPin.Id); if (annotationView == null) { annotationView = new CustomMKAnnotationView(annotation, customPin.Id); annotationView.Image = UIImage.FromFile("pin.png"); annotationView.CalloutOffset = new CGPoint(0, 0); annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("monkey.png")); annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); ((CustomMKAnnotationView)annotationView).Id = customPin.Id; ((CustomMKAnnotationView)annotationView).Url = customPin.Url; } annotationView.CanShowCallout = true; return annotationView; }
private void Initialize () { Title = Locale.GetText (""); _mapView = new MKMapView (); _mapView.AutoresizingMask = UIViewAutoresizing.All; _mapView.MapType = MKMapType.Standard; _mapView.ShowsUserLocation = true; _sgMapType = new UISegmentedControl (); _sgMapType.AutoresizingMask = UIViewAutoresizing.FlexibleMargins; _sgMapType.Opaque = true; _sgMapType.Alpha = 0.75f; _sgMapType.ControlStyle = UISegmentedControlStyle.Bar; _sgMapType.InsertSegment ("Map", 0, true); _sgMapType.InsertSegment ("Satellite", 1, true); _sgMapType.InsertSegment ("Hybrid", 2, true); _sgMapType.SelectedSegment = 0; _sgMapType.ValueChanged += (s, e) => { switch (_sgMapType.SelectedSegment) { case 0: _mapView.MapType = MKMapType.Standard; break; case 1: _mapView.MapType = MKMapType.Satellite; break; case 2: _mapView.MapType = MKMapType.Hybrid; break; } }; }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) return null; if (annotation is MonkeyAnnotation) { // show monkey annotation anView = mapView.DequeueReusableAnnotation (mId); if (anView == null) anView = new MKAnnotationView (annotation, mId); anView.Image = UIImage.FromFile ("monkey.png"); anView.CanShowCallout = true; anView.Draggable = true; anView.RightCalloutAccessoryView = UIButton.FromType (UIButtonType.DetailDisclosure); } else { // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation (pId); if (anView == null) anView = new MKPinAnnotationView (annotation, pId); ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Green; anView.CanShowCallout = true; } return anView; }
public override void ViewDidLoad() { _map = new MKMapView(); foreach(BusStop busStop in _busStops) { AddBusStopToMap(_map, busStop); } AddBusStopToMap(_map, _busStops[0]); _map.ShowsUserLocation = true; _map.Frame = new RectangleF (0, 0, this.View.Bounds.Width, this.View.Bounds.Height); if(_busStops.Length <= 1) { _map.Region = new MKCoordinateRegion(FindCentre(_busStops), new MKCoordinateSpan(0.005, 0.0005)); } else { _map.Region = RegionThatFitsAllStops(_busStops); } this.View.AddSubview (_map); }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; MKPointAnnotation anno = null; if (annotation is MKUserLocation) { return null; } else { anno = annotation as MKPointAnnotation; } string identifier = GetIdentifier (anno); if (identifier == "") throw new Exception ("No Identifier found for pin"); annotationView = mapView.DequeueReusableAnnotation (identifier); if (annotationView == null) annotationView = new CustomMKPinAnnotationView (annotation, identifier); //This removes the bubble that pops up with the title and everything ((CustomMKPinAnnotationView)annotationView).FormsIdentifier = identifier; annotationView.CanShowCallout = false; return annotationView; }
public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, IMKAnnotation annotation) { var extendedAnnotation = annotation as ExtendedMapAnnotation; if (extendedAnnotation == null) return null; // try and dequeue the annotation view var annotationView = mapView.DequeueReusableAnnotation(AnnotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) { annotationView = new MKAnnotationView(extendedAnnotation, AnnotationIdentifier); } else // if we did dequeue one for reuse, assign the annotation to it annotationView.Annotation = extendedAnnotation; // configure our annotation view properties annotationView.CanShowCallout = false; annotationView.Selected = true; if (!string.IsNullOrEmpty(extendedAnnotation.PinIcon)) { annotationView.Image = UIImage.FromFile(extendedAnnotation.PinIcon); } return annotationView; }
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 (); FoundCoords += (object sender, CoordEventArgs e) => { storageScreenContent.SetCoords(e.Latitude,e.Longitude); }; map = new MKMapView (UIScreen.MainScreen.Bounds); View = map; // create search controller searchBar = new UISearchBar (new RectangleF (0, 0, View.Frame.Width, 50)) { Placeholder = "Enter a search query" }; searchController = new UISearchDisplayController (searchBar, this); searchController.Delegate = new SearchDelegate (map); SearchSource source = new SearchSource (searchController, map); searchController.SearchResultsSource = source; source.FoundCoords += (object sender, CoordEventArgs e) => { var handler = FoundCoords; if(handler != null){ handler(this,e); } this.DismissViewController(true,null); }; View.AddSubview (searchBar); }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { var pet = ((CustomAnnotation)annotation).Model; var petAnnotationType = GetPetAnnotationType (pet); var pin = (MapAnnotationView)mapView.DequeueReusableAnnotation(petAnnotationType); string pinImage = petAnnotationType + ".png"; if (pin == null) { pin = new MapAnnotationView(annotation, petAnnotationType); pin.Image = UIImage.FromBundle(pinImage); pin.CenterOffset = new PointF (0, -15); } else { pin.Annotation = annotation; } pin.Draggable = _pinIsDraggable; pin.CanShowCallout = _canShowCallout; if (_canShowCallout) { Task.Run( async () => pin.LeftCalloutAccessoryView = await GetImage(pet)); pin.RightCalloutAccessoryView = GetDetailButton (pet); } return pin; }
UIButton detailButton; // need class-level ref to avoid GC /// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation (MKMapView mapView, NSObject annotation) { // try and dequeue the annotation view MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); else // if we did dequeue one for reuse, assign the annotation to it annotationView.Annotation = annotation; // configure our annotation view properties annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (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); detailButton.TouchUpInside += (s, e) => { var c = (annotation as MKAnnotation).Coordinate; new UIAlertView("Annotation Clicked", "You clicked on " + c.Latitude.ToString() + ", " + c.Longitude.ToString() , null, "OK", null).Show(); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("Images/Icon/29_icon.png")); //annotationView.Image = UIImage.FromBundle("Images/Apress-29x29.png"); return annotationView; }
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(); 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 MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { var pin = (MKAnnotationView)mapView.DequeueReusableAnnotation("zombie"); if (pin == null) { pin = new MKAnnotationView(annotation, "zombie"); pin.Image = UIImage.FromFile("zombie.png"); pin.CenterOffset = new PointF(0, -30); } else { pin.Annotation = annotation; } var zombieAnnotation = (ZombieAnnotation) annotation; if (zombieAnnotation.Zombie.IsMale) { //pin.PinColor = MKPinAnnotationColor.Purple; } else { //pin.PinColor = MKPinAnnotationColor.Red; } return pin; }
public override void ViewDidLoad () { base.ViewDidLoad (); Title = "MapView"; mapView = new MKMapView(View.Bounds); mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; //mapView.MapType = MKMapType.Standard; // this is the default //mapView.MapType = MKMapType.Satellite; //mapView.MapType = MKMapType.Hybrid; View.AddSubview(mapView); // create our location and zoom //CLLocationCoordinate2D coords = new CLLocationCoordinate2D(40.77, -73.98); // new york //CLLocationCoordinate2D coords = new CLLocationCoordinate2D(33.93, -118.40); // los angeles //CLLocationCoordinate2D coords = new CLLocationCoordinate2D(51.509, -0.1); // london CLLocationCoordinate2D coords = new CLLocationCoordinate2D(48.857, 2.351); // paris MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude)); // set the coords and zoom on the map mapView.Region = new MKCoordinateRegion(coords, span); }
public override void ViewDidLoad() { var mapView = new MKMapView(); View = mapView; base.ViewDidLoad(); // ios7 layout if (RespondsToSelector(new Selector("edgesForExtendedLayout"))) EdgesForExtendedLayout = UIRectEdge.None; var regionManager = new RegionManager(mapView); mapView.Delegate = regionManager; 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<FifthView, Core.ViewModels.FifthViewModel>(); set.Bind(regionManager).For(r => r.TheLocation).To(vm => vm.Location); set.Bind(button).For("Title").To(vm => vm.Location); set.Apply(); }
public override void ViewDidLoad() { base.ViewDidLoad (); Title = "Mi Ubicacion"; mapView = new MKMapView(View.Bounds); mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; //mapView.MapType = MKMapType.Standard; // this is the default //mapView.MapType = MKMapType.Satellite; mapView.MapType = MKMapType.Hybrid; mapView.ZoomEnabled = true; View.AddSubview(mapView); // this is all that's required to show the blue dot indicating user-location mapView.ShowsUserLocation = true; Console.WriteLine ("initial loc:"+mapView.UserLocation.Coordinate.Latitude + "," + mapView.UserLocation.Coordinate.Longitude); mapView.DidUpdateUserLocation += (sender, e) => { if (mapView.UserLocation != null) { Console.WriteLine ("userloc:"+mapView.UserLocation.Coordinate.Latitude + "," + mapView.UserLocation.Coordinate.Longitude); CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(1), MilesToLongitudeDegrees(1, coords.Latitude)); mapView.Region = new MKCoordinateRegion(coords, span); } }; if (!mapView.UserLocationVisible) { // user denied permission, or device doesn't have GPS/location ability Console.WriteLine ("userloc not visible, show cupertino"); CLLocationCoordinate2D coords = new CLLocationCoordinate2D(37.33233141,-122.0312186); // cupertino MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude)); mapView.Region = new MKCoordinateRegion(coords, span); } 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("Mapa", 0, false); mapTypes.InsertSegment("Satelite", 1, false); mapTypes.InsertSegment("Hibrido", 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); }
public override MKOverlayView GetViewForOverlay(MKMapView mapView, NSObject overlay) { var circleOverlay = overlay as MKCircle; var circleView = new MKCircleView (circleOverlay); circleView.FillColor = UIColor.Red; circleView.Alpha = 0.2f; return circleView; }
public GeocoderViewControllerAdapter(MvxViewController viewController, MKMapView mapView, Action<string> addressChanged) : base(viewController) { _geocoder = new CLGeocoder (); _addressChanged = addressChanged; mapView.RegionChanged += MapView_RegionChanged; mapView.SetRegion (new MapKit.MKCoordinateRegion (new CoreLocation.CLLocationCoordinate2D (45.5316085, -73.6227476), new MapKit.MKCoordinateSpan (0.01, 0.01)), animated: true); }
public void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView annotationView) { var annotation = annotationView.Annotation as BNRMapPoint; if (annotation != null) { Console.WriteLine("Weak DidSelectAnnotationView: {0}", annotation.Title); } }
public override void CalloutAccessoryControlTapped(MKMapView mapView, MKAnnotationView view, UIControl control) { // make sure its the right annotation var ann = view.Annotation as HeritagePropertyAnnotation; // call the callback if (ann != null && this.CalloutTappedCallback != null) CalloutTappedCallback(ann.Property); }
public override MKOverlayView GetViewForOverlay(MKMapView mapView, IMKOverlay overlay) { // return a view for the polygon MKPolygon polygon = overlay as MKPolygon; MKPolygonView polygonView = new MKPolygonView (polygon); polygonView.FillColor = UIColor.Blue; polygonView.StrokeColor = UIColor.Red; return polygonView; }
public MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is LocationAnnotation) { // Try to dequeue an existing pin view first. var pinView = (MKAnnotationView)mapView.DequeueReusableAnnotation("CustomPinAnnotationView"); if (pinView == null) { // If an existing pin view was not available, create one. pinView = new MKAnnotationView(annotation, @"CustomPinAnnotationView"); } //pinView.animatesDrop = YES; pinView.CanShowCallout = true; //pinView.Image = new UIImage(@"pizza_slice_32.png"); pinView.CalloutOffset = new CGPoint(0, 32); UILabel label; if (pinView.Subviews.Count() == 0) { label = new UILabel(); pinView.AddSubview(label); } else { label = pinView.Subviews[0] as UILabel; } label.Text = Convert.ToString((annotation as LocationAnnotation).LocationIndex); label.SizeToFit(); return(pinView); } else if (annotation is MKPointAnnotation) { return(new MKPinAnnotationView(annotation, null)); } else { return(null); } }
void AddMap() { mapView = new MKMapView(); mapView.TranslatesAutoresizingMaskIntoConstraints = false; this.View.AddSubview(mapView); var dict = new NSMutableDictionary(); dict.Add((NSString)"mainView", this.View); dict.Add((NSString)"mapView", mapView); dict.Add((NSString)"locationMessage", locationMessage); this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("H:|-[mapView]-|", NSLayoutFormatOptions.AlignAllTop, null, dict)); this.View.AddConstraints(NSLayoutConstraint.FromVisualFormat("V:[locationMessage]-[mapView]-|", NSLayoutFormatOptions.AlignAllCenterX, null, dict)); this.View.AddConstraints(new[] { NSLayoutConstraint.Create(locationMessage, NSLayoutAttribute.CenterX, NSLayoutRelation.Equal, titleLabel, NSLayoutAttribute.CenterX, 1, 0), }); }
UIButton detailButton; // avoid GC public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // try and dequeue the annotation view MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); } else // if we did dequeue one for reuse, assign the annotation to it { annotationView.Annotation = annotation; } // configure our annotation view properties annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (annotationView as MKPinAnnotationView).PinColor = MKPinAnnotationColor.Red; annotationView.Selected = true; // you can add an accessory view; in this case, a button on the right and an image on the left detailButton = UIButton.FromType(UIButtonType.DetailDisclosure); detailButton.TouchUpInside += (s, e) => { var cinemaAnnotation = (annotation as CinemaAnnotation); if (cinemaAnnotation == null) { return; } CinemaDetailsViewController cinemaDetails = cinemaAnnotation.Storyboard.InstantiateViewController("CinemaDetailsViewController") as CinemaDetailsViewController; if (cinemaDetails != null) { cinemaDetails.Cinema = cinemaAnnotation.Cinema; cinemaAnnotation.NavigationController.PushViewController(cinemaDetails, true); } }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("Images/SmallLogo.png")); return(annotationView); }
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); }
MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { //Stop annotations if (annotation is StopAnnotation) { StopAnnotation stopAnn = annotation as StopAnnotation; //dequeue or create MKPinAnnotationView pin = mapView.DequeueReusableAnnotation(STOP_PIN_ID) as MKPinAnnotationView; if (pin == null) { pin = new MKPinAnnotationView(stopAnn, STOP_PIN_ID); pin.CanShowCallout = true; } return(pin); } //end is stop annotations return(null); }
/// <summary> /// This is very much like the GetCell method on the table delegate /// </summary> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { // try and dequeue the annotation view MKAnnotationView annotationView = mapView.DequeueReusableAnnotation(annotationIdentifier); // if we couldn't dequeue one, create a new one if (annotationView == null) { annotationView = new MKPinAnnotationView(annotation, annotationIdentifier); } else // if we did dequeue one for reuse, assign the annotation to it { annotationView.Annotation = annotation; } // configure our annotation view properties annotationView.CanShowCallout = true; (annotationView as MKPinAnnotationView).AnimatesDrop = true; (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); detailButton.TouchUpInside += (s, e) => { Console.WriteLine("Clicked"); //Create Alert var detailAlert = UIAlertController.Create("Annotation Clicked", "You clicked on " + (annotation as MKAnnotation).Coordinate.Latitude.ToString() + ", " + (annotation as MKAnnotation).Coordinate.Longitude.ToString(), UIAlertControllerStyle.Alert); detailAlert.AddAction(UIAlertAction.Create("OK", UIAlertActionStyle.Default, null)); UIWebView webView = new UIWebView(); var url = "https://xamarin.com"; // NOTE: https secure request webView.LoadRequest(new NSUrlRequest(new NSUrl(url))); webView.Bounds = new CoreGraphics.CGRect(0, 0, 100, 100); detailAlert.Add(webView); parent.PresentViewController(detailAlert, true, null); }; annotationView.RightCalloutAccessoryView = detailButton; annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromBundle("29_icon.png")); return(annotationView); }
/// <summary> /// This is the callback for when the detail disclosure is clicked /// </summary> public override void CalloutAccessoryControlTapped(MKMapView mapView, MKAnnotationView view, UIControl control) { //This will launch apple's Maps app with the selected address var assignment = GetAssignment(view.Annotation as MKPlacemark); StringBuilder builder = new StringBuilder("http://maps.apple.com/maps?daddr="); builder.Append(assignment.Address.Replace(' ', '+')); builder.Append('+'); builder.Append(assignment.City.Replace(' ', '+')); builder.Append('+'); builder.Append(assignment.State); builder.Append('+'); builder.Append(assignment.Zip); builder.Append('+'); using (var url = NSUrl.FromString(builder.ToString())) { UIApplication.SharedApplication.OpenUrl(url); } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { var pin = (MKAnnotationView)mapView.DequeueReusableAnnotation("zombie"); if (pin == null) { pin = new MKAnnotationView(annotation, "zombie"); pin.Image = UIImage.FromFile("zombie.png"); pin.CenterOffset = new PointF(0, -30); } else { pin.Annotation = annotation; } pin.Draggable = true; return(pin); }
public virtual MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { if (annotation is MKUserLocation) { return(null); } MKAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pID); if (pinView == null) { pinView = new MKPinAnnotationView(annotation, pID); } ((MKPinAnnotationView)pinView).PinColor = MKPinAnnotationColor.Red; pinView.CanShowCallout = true; return(pinView); }
/// <summary> /// Retrieves a view for our annotations. /// </summary> /// <param name="mapView"></param> /// <param name="annotation"></param> /// <returns></returns> public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, NSObject annotation) { if (annotation.GetType() != typeof(ClusterAnnotation)) { return(MapViewViewForAnnotation(mapView, annotation)); } if (((ClusterAnnotation)annotation).Type == ClusterAnnotationType.Leaf) { return(MapViewViewForAnnotation(mapView, annotation)); } if (((ClusterAnnotation)annotation).Type == ClusterAnnotationType.Cluster) { return(MapViewViewForClusterAnnotation(mapView, annotation)); } return(null); }
public override void DidUpdateUserLocation(MKMapView mapView, MKUserLocation userLocation) { if (mapView.UserLocation != null) { MapDelegate1.color = 1; CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(1), MilesToLongitudeDegrees(1, coords.Latitude)); mapView.Region = new MKCoordinateRegion(coords, span); MapDelegate1.color = 3; mapView.AddAnnotation(new MKPointAnnotation() { Title = "Victim 5", Subtitle = "1 510 555-5555 - Rescue in progress", Coordinate = new CLLocationCoordinate2D(37.777257, -122.391061) }); } }
public static RadarBounds GetRadarBounds(this MKMapView map) { CLLocationCoordinate2D center = map.CenterCoordinate; var topLeft = MKMapPoint.FromCoordinate(new CLLocationCoordinate2D(center.Latitude + (map.Region.Span.LatitudeDelta / 2.0), center.Longitude - (map.Region.Span.LongitudeDelta / 2.0))); var bottomRight = MKMapPoint.FromCoordinate(new CLLocationCoordinate2D(center.Latitude - (map.Region.Span.LatitudeDelta / 2.0), center.Longitude + (map.Region.Span.LongitudeDelta / 2.0))); var bounds = new RadarBounds { MinLat = center.Latitude + (map.Region.Span.LatitudeDelta / 2.0), MaxLat = center.Latitude - (map.Region.Span.LatitudeDelta / 2.0), MinLon = center.Longitude - (map.Region.Span.LongitudeDelta / 2.0), MaxLon = center.Longitude + (map.Region.Span.LongitudeDelta / 2.0), Height = Math.Abs(topLeft.Y - bottomRight.Y), Width = Math.Abs(topLeft.X - bottomRight.X) }; return(bounds); }
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] }
public void Overlays() { using (var polygon = new MKPolygon()) using (var polyline = new MKPolyline()) using (var circle = new MKCircle()) using (MKMapView mv = new MKMapView()) { // old API accepted NSObject (limited protocol support) mv.AddOverlay(polygon); Assert.That(mv.Overlays.Length, Is.EqualTo(1), "1"); mv.RemoveOverlay(polygon); Assert.That(mv.Overlays, Is.Empty, "2"); IMKOverlay[] list = { polygon, polyline, circle }; mv.AddOverlays(list); Assert.That(mv.Overlays.Length, Is.EqualTo(3), "3"); mv.RemoveOverlays(list); Assert.That(mv.Overlays, Is.Empty, "4"); } }
public override void DidSelectAnnotationView(MKMapView mapView, MKAnnotationView view) { DeselectPin(); var unifiedPoint = view?.Annotation as UnifiedPointAnnotation; _selectedAnnotation = unifiedPoint; _selectedAnnotationView = view; if (unifiedPoint != null) { _renderer.SelectedItem = unifiedPoint.Data; var isSelected = unifiedPoint.Data?.SelectedImage != null; UpdateImage(view, unifiedPoint.Data, isSelected); UpdatePin(view, unifiedPoint.Data, true); view.Layer.ZPosition = int.MaxValue - 1; } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView anView; if (annotation is MKUserLocation) { return(null); } if (annotation is CustomAnnotation) { // show monkey annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); //MKAnnotationView pinView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (anView == null) { anView = new MKPinAnnotationView(annotation, mId); } //anView.Image = UIImage.FromFile("monkey.png"); anView.CanShowCallout = true; anView.Draggable = true; anView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure); //Optional anView.LeftCalloutAccessoryView = new UIImageView(UIImage.FromFile("monkey.png")); } else { // show pin annotation anView = (MKPinAnnotationView)mapView.DequeueReusableAnnotation(pId); if (anView == null) { anView = new MKPinAnnotationView(annotation, pId); } ((MKPinAnnotationView)anView).PinColor = MKPinAnnotationColor.Red; anView.CanShowCallout = true; } return(anView); }
protected override void Dispose(bool disposing) { if (disposing) { if (_MapView != null) { _MapView.Dispose(); _MapView = null; } if (GeocodeAnnotation != null) { GeocodeAnnotation.Dispose(); GeocodeAnnotation = null; } } base.Dispose(disposing); }
private void BuildMapView(LocationCoordinate currentLocation) { var visibleRegion = this.BuildVisibleRegion(currentLocation); this.mapView = new MKMapView() { ShowsUserLocation = true, ZoomEnabled = true }; this.mapView.SizeToFit(); this.mapView.Frame = new RectangleF(0, this.toolbar.Bounds.Height, this.View.Frame.Width, this.View.Frame.Height - this.toolbar.Bounds.Height); this.mapView.SetRegion(visibleRegion, true); this.mapView.Delegate = this.GeofenceMapDelegate; this.View.AddSubview(this.toolbar); this.View.AddSubview(this.mapView); this.SetupGestureInteraction(); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (isLoaded) { nativeMap.RemoveOverlays(nativeMap.Overlays); } if (e.OldElement != null) { nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = null; } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; nativeMap = Control as MKMapView; isCircle = formsMap.DrawCircle; if (!isCircle) { nativeMap.OverlayRenderer = GetOverlayRenderer; CLLocationCoordinate2D[] coords = new CLLocationCoordinate2D[formsMap.RouteCoordinates.Count]; int index = 0; foreach (var position in formsMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } var routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); } if (isCircle) { var circle = formsMap.Circle; nativeMap.OverlayRenderer = GetOverlayRenderer; var circleOverlay = MKCircle.Circle(new CoreLocation.CLLocationCoordinate2D(circle.Position.Latitude, circle.Position.Longitude), circle.Radius); nativeMap.AddOverlay(circleOverlay); } } }
public MKPolylineEx(MKMapView map, List <MKPolylineEx> polylines, CLLocationCoordinate2D[] coordinates) { _map = map; _collection = polylines; var idxStart = 0; while (idxStart < coordinates.Length) { var coordsToAdd = new List <CLLocationCoordinate2D>(); for (var i = idxStart; i < Math.Min(idxStart + PolylineSegmentLength + 1, coordinates.Length); i++) { coordsToAdd.Add(coordinates[i]); } var polylineToAdd = MKPolyline.FromCoordinates(coordsToAdd.ToArray()); _polylines.Add(polylineToAdd); idxStart += PolylineSegmentLength; } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { // release event bindings if (_nativeMap != null) { _nativeMap.GetViewForAnnotation = null; _nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; _nativeMap = null; } var notifyingCollection = _customMap?.CustomPins as INotifyCollectionChanged; if (notifyingCollection != null) { notifyingCollection.CollectionChanged += PinCollectionChanged; } } if (e.NewElement != null) { // create event bindings _nativeMap = Control as MKMapView; _customMap = e.NewElement as CustomMap; if (_nativeMap != null) { _nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; _nativeMap.GetViewForAnnotation = GetViewForAnnotation; } var notifyingCollection = _customMap?.CustomPins as INotifyCollectionChanged; if (notifyingCollection != null) { notifyingCollection.CollectionChanged += PinCollectionChanged; } CreateNewAnnotations(_customMap?.CustomPins); } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); if (e.OldElement != null) { nativeMap = Control as MKMapView; nativeMap.OverlayRenderer = null; #region For different pin images nativeMap.GetViewForAnnotation = null; nativeMap.CalloutAccessoryControlTapped -= OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView -= OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView -= OnDidDeselectAnnotationView; #endregion } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; nativeMap = Control as MKMapView; customPins = new List <Pin>(formsMap.Pins); nativeMap.OverlayRenderer = GetOverlayRenderer; int index = 0; foreach (var position in CustomMap.RouteCoordinates) { coords[index] = new CLLocationCoordinate2D(position.Latitude, position.Longitude); index++; } routeOverlay = MKPolyline.FromCoordinates(coords); nativeMap.AddOverlay(routeOverlay); nativeMap.ScrollEnabled = true; #region For different pin images nativeMap.GetViewForAnnotation = GetViewForAnnotation; nativeMap.CalloutAccessoryControlTapped += OnCalloutAccessoryControlTapped; nativeMap.DidSelectAnnotationView += OnDidSelectAnnotationView; nativeMap.DidDeselectAnnotationView += OnDidDeselectAnnotationView; #endregion } }
public override void ViewDidLoad() { var mapView = new MKMapView(); View = mapView; base.ViewDidLoad(); // ios7 layout if (RespondsToSelector(new Selector("edgesForExtendedLayout"))) { EdgesForExtendedLayout = UIRectEdge.None; } var firstViewModel = (FourthViewModel)ViewModel; _regionManager = new RegionManager(mapView); var button = new UIButton(UIButtonType.RoundedRect); button.Frame = new RectangleF(10, 10, 300, 40); button.SetTitle("move", UIControlState.Normal); Add(button); var lat = new UITextField(new RectangleF(10, 50, 130, 40)); lat.KeyboardType = UIKeyboardType.DecimalPad; Add(lat); var lng = new UITextField(new RectangleF(160, 50, 130, 40)); lng.KeyboardType = UIKeyboardType.DecimalPad; Add(lng); var set = this.CreateBindingSet <FourthView, Core.ViewModels.FourthViewModel>(); set.Bind(button).To(vm => vm.UpdateCenterCommand); set.Bind(lat).To(vm => vm.Lat); set.Bind(lng).To(vm => vm.Lng); set.Bind(_regionManager).For(r => r.Center).To(vm => vm.Location); set.Apply(); }
public void StartMaps() { MapShow.Hidden = false; // MapCloseButton.Hidden = false; mapView = MapShow; CLLocationManager location = new CLLocationManager(); mapView.ShowsUserLocation = true; CLLocationManager locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); UpdateBus(); }
protected override void OnElementChanged(Xamarin.Forms.Platform.iOS.ElementChangedEventArgs <View> e) { base.OnElementChanged(e); nativeMap = Control as MKMapView; formsMap = Element as CustomMap; if (e.OldElement != null) { nativeMap.Delegate = null; formsMap.ItemsSource.CollectionChanged -= ItemsSource_CollectionChanged; } if (e.NewElement != null) { nativeMap.Delegate = null; nativeMap.Delegate = new MapDelegate(formsMap, nativeMap); formsMap.ItemsSource.CollectionChanged += ItemsSource_CollectionChanged; } }
public virtual MKOverlayRenderer OverlayRenderer(MKMapView mapView, IMKOverlay overlay) { if (overlay is MKPolyline) { Console.WriteLine("get renderer for overlay"); var renderer = new MKPolylineRenderer(overlay as MKPolyline); if (overlay.GetTitle() == "direction") { renderer.StrokeColor = UIColor.Blue.ColorWithAlpha(0.1f); } else { renderer.StrokeColor = UIColor.Red.ColorWithAlpha(0.5f); } renderer.LineWidth = 10; return(renderer); } return(null); }
public override void ViewDidLoad() { base.ViewDidLoad(); MKMapView mapView = new MKMapView(View.Bounds); NavigationItem.Title = "Ubicación"; mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; View.AddSubview(mapView); var ann = new MKPointAnnotation[] { new MKPointAnnotation() { Title = "Universidad de la Salle Bajío", Coordinate = coordenada[0] }, new MKPointAnnotation() { Title = lugar, Coordinate = coordenada[1] } }; Do_Rute(Add_Annotation(ann, coordenada, mapView), UIColor.Green, coordenada, mapView); }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (e.OldElement != null) { this.nativeMap = Control as MKMapView; this.nativeMap.GetViewForAnnotation = null; } if (e.NewElement != null) { var formsMap = (CustomMap)e.NewElement; this.nativeMap = Control as MKMapView; this.customPins = formsMap.CustomPins; nativeMap.GetViewForAnnotation = GetViewForAnnotation; updateAllPins(); } }
public override void ViewDidLoad() { var mapView = new MKMapView(); mapView.Delegate = new MyDelegate(); View = mapView; base.ViewDidLoad(); var mapViewModel = (MapViewModel)ViewModel; var keithAnnotation = new ItemAnnotation(mapViewModel); mapView.AddAnnotation(keithAnnotation); mapView.SetRegion(MKCoordinateRegion.FromDistance( new CLLocationCoordinate2D(mapViewModel.Latitude, mapViewModel.Longitude), 200, 200), true); }
/// <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); } }
public override MKAnnotationView GetViewForAnnotation(MKMapView mapView, IMKAnnotation annotation) { MKAnnotationView annotationView = null; if (annotation is MKUserLocation) return null; if (annotation is CarAnnotation) { annotationView = mapView.DequeueReusableAnnotation(CarAnnotation) ?? new MKAnnotationView(annotation, CarAnnotation); if (((CarAnnotation) annotation).Color == UIColor.Blue) { annotationView.Image = UIImage.FromBundle(Images.CarAnnotationBlue); } else { annotationView.Image = UIImage.FromBundle(Images.CarAnnotationRed); } annotationView.CanShowCallout = false; } if (annotation is PoiAnnotation) { annotationView = mapView.DequeueReusableAnnotation(POI_ANNOTATION) ?? new MKAnnotationView(annotation, POI_ANNOTATION); if (((PoiAnnotation) annotation).Description == "Hard Acceleration") { annotationView.Image = UIImage.FromBundle(Images.TipAnnotation); } else { annotationView.Image = UIImage.FromBundle(Images.TipAnnotation); } annotationView.CanShowCallout = false; } if (annotation is WaypointAnnotation) { annotationView = mapView.DequeueReusableAnnotation(WaypointAnnotation) ?? new MKAnnotationView(annotation, WaypointAnnotation); if (((WaypointAnnotation) annotation).Waypoint == "A") { annotationView.Image = UIImage.FromBundle(Images.WaypointAnnotationA); } else { annotationView.Image = UIImage.FromBundle(Images.WaypointAnnotationB); } annotationView.CanShowCallout = false; } return annotationView; }
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); } }