private static Position ConvertLocationToPosition(UIGestureRecognizer recognizer, MKMapView map) { var point = recognizer.LocationInView(map); var coordinate = map.ConvertPoint(point, map); return(new Position(coordinate.Latitude, coordinate.Longitude)); }
public override void ViewDidLoad() { base.ViewDidLoad(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { locationManager.RequestWhenInUseAuthorization(); } // change map type, show user location and allow zooming and panning map.MapType = MKMapType.Standard; map.ShowsUserLocation = true; map.ZoomEnabled = true; map.ScrollEnabled = true; // set map center and region double lat = 30.2652233534254; double lon = -97.73815460962083; CLLocationCoordinate2D mapCenter = new CLLocationCoordinate2D(lat, lon); MKCoordinateRegion mapRegion = MKCoordinateRegion.FromDistance(mapCenter, 100, 100); map.CenterCoordinate = mapCenter; map.Region = mapRegion; // set the map delegate mapDelegate = new MapDelegate(); map.Delegate = mapDelegate; // add a custom annotation at the map center map.AddAnnotations(new ConferenceAnnotation("Evolve Conference", mapCenter)); // add an overlay of the hotel MKPolygon hotelOverlay = MKPolygon.FromCoordinates( new CLLocationCoordinate2D[] { new CLLocationCoordinate2D(30.2649977168594, -97.73863627705), new CLLocationCoordinate2D(30.2648461170005, -97.7381627734755), new CLLocationCoordinate2D(30.2648355402574, -97.7381750192576), new CLLocationCoordinate2D(30.2647791309417, -97.7379872505988), new CLLocationCoordinate2D(30.2654525150319, -97.7377341711021), new CLLocationCoordinate2D(30.2654807195004, -97.7377994819399), new CLLocationCoordinate2D(30.2655089239607, -97.7377994819399), new CLLocationCoordinate2D(30.2656428950368, -97.738346460207), new CLLocationCoordinate2D(30.2650364981811, -97.7385709662122), new CLLocationCoordinate2D(30.2650470749025, -97.7386199493406) }); map.AddOverlay(hotelOverlay); UITapGestureRecognizer tap = new UITapGestureRecognizer(g => { var pt = g.LocationInView(map); CLLocationCoordinate2D tapCoord = map.ConvertPoint(pt, map); Console.WriteLine("new CLLocationCoordinate2D({0}, {1}),", tapCoord.Latitude, tapCoord.Longitude); }); map.AddGestureRecognizer(tap); }
protected void OnMapLongTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); if (annotationMode) { foreach (var annotation in annotations) { // var annotation = new MKPointAnnotation(tappedLocationCoord, "User annotation", ""); if (annotation.Coordinate.Latitude == tappedLocationCoord.Latitude && annotation.Coordinate.Longitude == tappedLocationCoord.Longitude) { map.RemoveAnnotation(annotation); annotations.Remove(annotation); } } } }
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(); }
void HandleTap(UITapGestureRecognizer g) { if (map == null) { return; } if (g.State != UIGestureRecognizerState.Recognized) { return; } var c = map.ConvertPoint(g.LocationInView(map), map); Tapped(this, new MapTappedEventArgs { Coordinate = new MapCoordinate(c.Latitude, c.Longitude) }); }
protected async void OnMapTapped(UIGestureRecognizer sender) { CLLocationCoordinate2D tappedLocationCoord = map.ConvertPoint(sender.LocationInView(map), map); map.RemoveAnnotations(map.Annotations); map.AddAnnotations(new MKPointAnnotation() { Title = "Выбранная геопозиция", Coordinate = tappedLocationCoord }); int button = await ShowAlert("Вы уверены?", "Выбрать геопозицию?", "Да", "Нет"); if (button == 0) { map.RemoveFromSuperview(); } }
public override void TouchesEnded(NSSet touches, UIEvent evt) { base.TouchesEnded(touches, evt); List <CLLocationCoordinate2D> CoordinateList = new List <CLLocationCoordinate2D>(); pointlist.ForEach(Point => { CoordinateList.Add(MapView.ConvertPoint(Point, MapView)); }); if (CoordinateList.Count > 0) { MapView.AddOverlay(MKPolyline.FromCoordinates(CoordinateList.ToArray())); } pointlist = new List <CGPoint>(); }
public void LongPress(UILongPressGestureRecognizer touches) { if (touches.State == UIGestureRecognizerState.Ended) { CGPoint location = touches.LocationInView(_map); CLLocationCoordinate2D coordinate = _map.ConvertPoint(location, _map); _marcerRow = new MapMarkerEntity(); _marcerRow.Latitude = coordinate.Latitude; _marcerRow.Longitude = coordinate.Longitude; ViewModel.SaveMarkerInList(_marcerRow); _map.AddAnnotations(new MKPointAnnotation() { Title = Constants.MapMarker, Coordinate = new CLLocationCoordinate2D(coordinate.Latitude, coordinate.Longitude) }); } }
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; } }
private void LongPress(UILongPressGestureRecognizer gesture) { _mKMapView.RemoveAnnotations(_mKMapView.Annotations); CGPoint touchPoint = gesture.LocationInView(_mKMapView); CLLocationCoordinate2D touchMapCoordinate = _mKMapView.ConvertPoint(touchPoint, _mKMapView); MKAnnotationClass annotation = new MKAnnotationClass(); annotation.Coordinate2D = touchMapCoordinate; _lalitude = annotation.Coordinate2D.Latitude; _longitude = annotation.Coordinate2D.Longitude; _customMap.UserLalitude = _lalitude; _customMap.UserLongitude = _longitude; _mKMapView.AddAnnotation(annotation); _mKMapView.AddAnnotations(new MKPointAnnotation() { Coordinate = new CLLocationCoordinate2D(_lalitude, _longitude) }); }
private void MapTapped(MKMapView mapView, UITapGestureRecognizer tappedGesture) { var mapview = tappedGesture.View as MKMapView; CLLocationCoordinate2D coord2D = mapView.ConvertPoint(tappedGesture.LocationInView(mapView), mapView); var mapPoint = MKMapPoint.FromCoordinate(coord2D); foreach (IMKOverlay overlay in mapview.Overlays) { var renderer = (MKOverlayPathRenderer)mapview.RendererForOverlay(overlay); if (renderer == null) { return; } var polyTouched = renderer.Path.ContainsPoint(renderer.PointForMapPoint(mapPoint), true); if (polyTouched) { //Do something } } }
public override void TouchesBegan(NSSet touches, UIEvent evt) { UITouch aTouch = (UITouch)touches.AnyObject; PointF location = aTouch.LocationInView(this); Debug.WriteLine("TouchesBegan {0},{1}", location.X, location.Y); var coordinate = MapView.ConvertPoint(location, this); switch (geometry.Type) { case GeometryType.Point: if (geometry.Count == 1) { var point = geometry[0]; MapView.RemoveAnnotation(point); geometry.Remove(geometry[0]); var newPoint = new PointAnnotation(coordinate); geometry.Add(newPoint); MapView.AddAnnotation(newPoint); } else { var point = new PointAnnotation(coordinate); geometry.Add(point); MapView.AddAnnotation(point); } break; case GeometryType.Line: var _point = new PointAnnotation(coordinate); geometry.Add(_point); foreach (var a in annotationViewsArray) { MapView.RemoveAnnotation(a as MKAnnotation); } annotationViewsArray.Clear(); if (geometry.Count >= 2) { var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type); MapView.AddAnnotation(_lineAnnotation); annotationViewsArray.Add(_lineAnnotation); } MapView.AddAnnotation(_point); break; case GeometryType.Polygon: var __point = new PointAnnotation(coordinate); geometry.Add(__point); foreach (var a in annotationViewsArray) { MapView.RemoveAnnotation(a as MKAnnotation); } annotationViewsArray.Clear(); if (geometry.Count == 2) { var _lineAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type); MapView.AddAnnotation(_lineAnnotation); annotationViewsArray.Add(_lineAnnotation); } else { var _polygonAnnotation = new GeometryAnnotation(geometry.Points, geometry.Type); MapView.AddAnnotation(_polygonAnnotation); annotationViewsArray.Add(_polygonAnnotation); } MapView.AddAnnotation(__point); break; default: break; } }