public override void ViewDidLoad() { Console.WriteLine("Map to load"); base.ViewDidLoad (); Title = "MapView"; //mapView = new MKMapView(View.Bounds); this.DDZMapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; //this.DDZMapView.MapType = MKMapType.Standard; // this is the default //this.DDZMapView.MapType = MKMapType.Satellite; //this.DDZMapView.MapType = MKMapType.Hybrid; View.AddSubview(this.DDZMapView); // create our location and zoom CLLocationCoordinate2D coords = new CLLocationCoordinate2D(38.9686111, -77.3413889); // Reston MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude)); // set the coords and zoom on the map this.DDZMapView.Region = new MKCoordinateRegion(coords, span); circleOverlay = MKCircle.Circle (coords, 200); this.DDZMapView.AddOverlay (circleOverlay); this.DDZMapView.GetViewForOverlay = (m, o) => { if(circleView == null) { circleView = new MKCircleView(o as MKCircle); circleView.FillColor = UIColor.Purple; circleView.Alpha = 0.5f; } return circleView; }; }
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() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. ConfigureView(); _iPhoneLocationManager = new CLLocationManager(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { _iPhoneLocationManager.RequestWhenInUseAuthorization(); } mapView.ShowsUserLocation = true; if (mapView.UserLocationVisible) { UpdateUiCoords(); } _iPhoneLocationManager.DesiredAccuracy = 1000; // 1000 meters/1 kilometer mapView.DidUpdateUserLocation += (sender, e) => { if (mapView.UserLocation != null) { CLLocationCoordinate2D coords = mapView.UserLocation.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coords.Latitude)); mapView.Region = new MKCoordinateRegion(coords, span); UpdateUiCoords(); } }; }
public override void ViewDidLoad () { base.ViewDidLoad (); this.Title = "Pyramids of Giza"; // create our location and zoom for the pyramids. CLLocationCoordinate2D coords = new CLLocationCoordinate2D(29.976111, 31.132778); MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude)); // set the coords and zoom on the map this.mapMain.Region = new MKCoordinateRegion(coords, span); // show the sat view. this.mapMain.MapType = MKMapType.Satellite; // add an overlay with the coords this._circleOverlay = MKCircle.Circle(coords, 200); this.mapMain.AddOverlay(this._circleOverlay); // set our delegate. //this.mapMain.Delegate = new MapDelegate(); //-- OR -- //- override the GetVIewForOverlay directly, in which case we don't need a delegate this.mapMain.GetViewForOverlay += (m, o) => { if(this._circleView == null) { this._circleView = new MKCircleView(this._circleOverlay); this._circleView.FillColor = UIColor.Blue; this._circleView.Alpha = 0.5f; } return this._circleView; }; }
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 } })); }
async Task SearchAsync (string what, string where) { var coord = here == null ? Parse (where) : here.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan (0.25, 0.25); MKLocalSearchRequest request = new MKLocalSearchRequest (); request.Region = new MKCoordinateRegion (coord, span); request.NaturalLanguageQuery = what; MKLocalSearch search = new MKLocalSearch (request); MKLocalSearchResponse response; try{ response = await search.StartAsync (); } catch(Exception e){ return; } if (response == null) return; var section = new Section ("Search Results for " + what); results.Clear (); foreach (MKMapItem mi in response.MapItems) { results.Add (mi); var element = new StyledStringElement (mi.Name, mi.PhoneNumber, UITableViewCellStyle.Subtitle); element.Accessory = UITableViewCellAccessory.DisclosureIndicator; element.Tapped += () => { results [element.IndexPath.Row].OpenInMaps (); }; section.Add (element); } var root = new RootElement ("MapKit Search Sample") { section }; var dvc = new DialogViewController (root); (window.RootViewController as UINavigationController).PushViewController (dvc, true); }
public override void ViewDidLoad () { base.ViewDidLoad (); Title = "Highland Park, Los Angeles"; // create our location and zoom for los angeles CLLocationCoordinate2D coords = new CLLocationCoordinate2D (34.120, -118.188); MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees (20), MilesToLongitudeDegrees (20, coords.Latitude)); // set the coords and zoom on the map mapMain.Region = new MKCoordinateRegion (coords, span); // set our delegate. we don't actually need a delegate if we want to just drop a pin // on there, but if we want to specify anything custom, we do mapMain.Delegate = new MapDelegate(); // add a basic annotation mapMain.AddAnnotation (new BasicMapAnnotation (new CLLocationCoordinate2D (34.120, -118.188), "Los Angeles", "City of Demons")); // can use this as well. // mapMain.AddAnnotationObject( // new BasicMapAnnotationProto() { Coordinate = new CLLocationCoordinate2D(34.120, -118.188), Title = "Los Angeles", Subtitle = "City of Demons" } // ); }
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); }
partial void ZoomIn (NSObject obj) { var span = new MKCoordinateSpan (currentSpan.LatitudeDelta * 0.5f, currentSpan.LongitudeDelta * 0.5f); var region = new MKCoordinateRegion (currentRegion.Center, span); currentSpan = span; map.SetRegion (region); }
public void UpdateLocation(CLLocationCoordinate2D newLocation, bool animated){ var span = new MKCoordinateSpan(0.1,0.1); var region = new MKCoordinateRegion(newLocation, span); _mapView.SetRegion(region, animated); if (_geocodeAnnotation!=null) _mapView.RemoveAnnotation(_geocodeAnnotation); _geocodeAnnotation = new MapViewAnnotation(newLocation); _mapView.AddAnnotationObject(_geocodeAnnotation); }
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 (); } }
public override void ViewDidLoad() { base.ViewDidLoad (); Title = "Pyramids of Giza"; mapView = new MKMapView(View.Bounds); mapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions; View.AddSubview(mapView); var coords = new CLLocationCoordinate2D(29.976111, 31.132778); // pyramids of giza, egypt var span = new MKCoordinateSpan(MilesToLatitudeDegrees(.75), MilesToLongitudeDegrees(.75, coords.Latitude)); // set the coords and zoom on the map mapView.MapType = MKMapType.Satellite; mapView.Region = new MKCoordinateRegion(coords, span); mapView.OverlayRenderer = (m, o) => { if(circleRenderer == null) { circleRenderer = new MKCircleRenderer(o as MKCircle); circleRenderer.FillColor = UIColor.Purple; circleRenderer.Alpha = 0.5f; } return circleRenderer; }; circleOverlay = MKCircle.Circle (coords, 200); mapView.AddOverlay (circleOverlay); #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.InsertSegment("Road", 0, false); mapTypes.InsertSegment("Satellite", 1, false); mapTypes.InsertSegment("Hybrid", 2, false); mapTypes.SelectedSegment = 1; // 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 }
//track user's location and update the map showing the location closer public void trackLocation() { 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); } _message = String.Format("{0:f2}", map.UserLocation.Location.Speed < 0 ? 0 : (map.UserLocation.Location.Speed* 2.23694)); this.NavigationItem.Title = _message + " MPH"; }; }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear (animated); //Load the placemark and by default zoom into the placemark MKPlacemark placemark = assignmentViewModel.SelectedAssignment.ToPlacemark(); var span = new MKCoordinateSpan(1, 1); var region = new MKCoordinateRegion(placemark.Coordinate, span); mapView.ClearPlacemarks (); mapView.AddAnnotation (placemark); mapView.SetRegion (region, false); }
void LocationManager_LocationsUpdated(object sender, CLLocationsUpdatedEventArgs e) { locationManager.StopUpdatingLocation(); if (!map.UserLocationVisible) { CLLocationCoordinate2D coords = e.Locations[0].Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(Utility.MilesToLatitudeDegrees(2), Utility.MilesToLongitudeDegrees(2, coords.Latitude)); map.SetRegion(new MKCoordinateRegion(coords, span), true); ServiceLayer.SharedInstance.UserLocation = new Coordinates(coords.Latitude, coords.Longitude); } var app = UIApplication.SharedApplication.Delegate as AppDelegate; app.CurrentLocation = e.Locations.First(); }
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); // 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.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(); Title = "User Location"; 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); //Request permission to access device location - necessary on iOS 8.0 and above //Don't forget to set NSLocationWhenInUseUsageDescription in Info.plist locationManager.RequestWhenInUseAuthorization(); // this is 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(2), MilesToLongitudeDegrees(2, 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 CGRect((View.Bounds.Width - typesWidth) / 2, View.Bounds.Height - distanceFromBottom, typesWidth, typesHeight)); mapTypes.BackgroundColor = UIColor.White; mapTypes.Layer.CornerRadius = 5; mapTypes.ClipsToBounds = true; View.AddSubview(mapTypes); }
private void prepareMap() { var markLocation = new CoreLocation.CLLocationCoordinate2D(ViewMark.Latitude, ViewMark.Longitude); var coordinateSpan = new MKCoordinateSpan(0.01, 0.01); var coordinateRegion = new MKCoordinateRegion(markLocation, coordinateSpan); mapView.SetRegion(coordinateRegion, false); var pin = new MKPointAnnotation() { Title = ViewMark.Message, Coordinate = markLocation }; mapView.AddAnnotation(pin); }
private void prepareMap() { locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); mvDeliver.ShowsUserLocation = true; var span = new MKCoordinateSpan(0.15, 0.15); var coordinate = new CLLocationCoordinate2D(delivery.DestLat, delivery.DestLong); mvDeliver.Region = new MKCoordinateRegion(coordinate, span); mvDeliver.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinate, Title = "Drop Package" }); }
private void MvOrgin_DidUpdateUserLocation(object sender, MapKit.MKUserLocationEventArgs e) { if (mvOrgin.UserLocation != null) { var cordinate = mvOrgin.UserLocation.Coordinate; var span = new MKCoordinateSpan(0.15, 0.15); mvOrgin.Region = new MKCoordinateRegion(cordinate, span); mvOrgin.RemoveAnnotations(); mvOrgin.AddAnnotation(new MKPointAnnotation() { Coordinate = cordinate, Title = "Your Location" }); } }
public override void ViewDidLoad() { base.ViewDidLoad(); SetUpAnnotations(); CloseButton = UIButton.FromType(UIButtonType.Custom); CloseButton.SetTitle("X", UIControlState.Normal); CloseButton.BackgroundColor = UIColor.Green; CloseButton.SizeToFit(); CloseButton.TouchUpInside += (sender, e) => { Console.WriteLine("Close map"); DismissViewController(true, null); }; View.AddSubview(CloseButton); Map.ShowsUserLocation = true; Map.ShowsCompass = true; Map.AddGestureRecognizer((longPressGestureRecognizer = new UILongPressGestureRecognizer(OnMapLongPress))); doubleTapGestureRecognizer = new UITapGestureRecognizer() { NumberOfTapsRequired = 2 }; tapGestureRecognizer = new UITapGestureRecognizer(OnMapClicked); tapGestureRecognizer.RequireGestureRecognizerToFail(doubleTapGestureRecognizer); tapGestureRecognizer.ShouldReceiveTouch = (recognizer, touch) => !(touch.View is MKAnnotationView); Map.AddGestureRecognizer(tapGestureRecognizer); Map.AddGestureRecognizer(doubleTapGestureRecognizer); //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); // } //}; 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); } }
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 }
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); }
public void UpdateLocation(CLLocationCoordinate2D newLocation, bool animated) { var span = new MKCoordinateSpan(0.1, 0.1); var region = new MKCoordinateRegion(newLocation, span); _MapView.SetRegion(region, animated); if (GeocodeAnnotation != null) { _MapView.RemoveAnnotation(GeocodeAnnotation); } GeocodeAnnotation = new MapViewAnnotation(newLocation); _MapView.AddAnnotationObject(GeocodeAnnotation); }
private void DestinatinMapView_DidUpdateUserLocation(object sender, MapKit.MKUserLocationEventArgs e) { if (destinatinMapView.UserLocation != null) { var coordinates = destinatinMapView.UserLocation.Coordinate; var span = new MKCoordinateSpan(0.15, 0.15); destinatinMapView.Region = new MKCoordinateRegion(coordinates, span); destinatinMapView.RemoveAnnotations(); destinatinMapView.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinates, Title = "Точка 2" }); } }
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) }); } }
private void PrepareMap() { locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); deliveryMapView.ShowsUserLocation = true; var sapn = new MKCoordinateSpan(0.15, 0.15); var coordinates = new CLLocationCoordinate2D(delivery.DestinationLatitude, delivery.DestinationLongitude); deliveryMapView.Region = new MKCoordinateRegion(coordinates, sapn); deliveryMapView.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinates, Title = "Deliver here" }); }
//add pin void OriginMapViewIcon_DidUpdateUserLocation1(object sender, MKUserLocationEventArgs e) { if (originMapViewIcon.UserLocation != null) { var coordinates = originMapViewIcon.UserLocation.Coordinate; var span = new MKCoordinateSpan(0.15, 0.15); originMapViewIcon.Region = new MKCoordinateRegion(coordinates, span); //add title to the location originMapViewIcon.RemoveAnnotations(); originMapViewIcon.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinates, Title = "Your location" }); } }
void UpdateMap(object sender, EventArgs e) { CLLocationCoordinate2D coords = new CLLocationCoordinate2D(); if (!m_SearchMap.UserLocationVisible) { coords = m_SearchMap.UserLocation.Coordinate; } if (m_SearchMap.UserLocation != null) { coords = m_SearchMap.UserLocation.Coordinate; } MKCoordinateSpan span = new MKCoordinateSpan(KilometresToLatitudeDegrees(10), KilometresToLongitudeDegrees(10, coords.Latitude)); m_SearchMap.Region = new MKCoordinateRegion(coords, span); }
private void PrepareMap(StudentLocationModel slm) { try { if (mapview.Annotations != null) { mapview.RemoveAnnotations(mapview.Annotations); } //foreach (var item in mapview.Annotations) //{ // mapview.RemoveAnnotation(item); //} mapview.SetNeedsDisplay(); CLLocationCoordinate2D coordsforStudent = new CLLocationCoordinate2D(slm.student_lat, slm.student_lng); MKCoordinateSpan span1 = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coordsforStudent.Latitude)); mapview.Region = new MKCoordinateRegion(coordsforStudent, span1); CLLocationCoordinate2D coordsforSource = new CLLocationCoordinate2D(slm.source_lat, slm.source_lng); MKCoordinateSpan span2 = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coordsforSource.Latitude)); mapview.Region = new MKCoordinateRegion(coordsforSource, span2); CLLocationCoordinate2D coordsfordestinatin = new CLLocationCoordinate2D(slm.destination_lat, slm.destination_lng); MKCoordinateSpan span3 = new MKCoordinateSpan(MilesToLatitudeDegrees(2), MilesToLongitudeDegrees(2, coordsfordestinatin.Latitude)); mapview.Region = new MKCoordinateRegion(coordsfordestinatin, span3); // set the map delegate mapDel = new MyMapDelegate(); mapview.Delegate = mapDel; // add a custom annotation mapview.AddAnnotation(new CustomAnnotation(0, StaticDataModel.StudentInfo + "'s Home", coordsforStudent)); mapview.AddAnnotation(new CustomAnnotation(1, "Source", coordsforSource)); mapview.AddAnnotation(new CustomAnnotation(2, "Destination", coordsfordestinatin)); //// add a custom annotationTesting prupose //CLLocationCoordinate2D coords1 = new CLLocationCoordinate2D(StaticDataModel.Lattitude, StaticDataModel.Longitude); //mapview.AddAnnotation(new CustomAnnotation("Bus",coords1)); } catch (Exception ex) { } }
public Section5NativeB() { Body = () => new VStack { new UIViewRepresentable <MKMapView>() { MakeView = () => new MKMapView(UIScreen.MainScreen.Bounds), UpdateView = (view, data) => { var coordinate = new CLLocationCoordinate2D(latitude: 34.011286, longitude: -116.166868); var span = new MKCoordinateSpan(latitudeDelta: 2.0, longitudeDelta: 2.0); var region = new MKCoordinateRegion(center: coordinate, span: span); view.SetRegion(region, animated: true); } } }; }
public override void ViewDidLoad() { base.ViewDidLoad(); MvxFluentBindingDescriptionSet <DetailView, DetailViewModel> set = this.CreateBindingSet <DetailView, DetailViewModel>(); //Kleur Tekst in baar this.NavigationController.NavigationBar.TintColor = UIColor.White; //Titel geven aan pagina set.Bind(this).For(v => v.Title).To(vm => vm.ParkingContent.description); //"Back" instellen ipv "Live Parking" //this.NavigationController.NavigationBar.TopItem.Title = "Back"; set.Bind(lblParkingName).To(vm => vm.ParkingContent.description); set.Bind(lblAddress).To(vm => vm.ParkingContent.address); set.Bind(lblFreePlaces).To(vm => vm.ParkingContent.parkingStatus.availableCapacity); set.Bind(btnNavigate).To(vm => vm.NavigateCommand); set.Bind(lblPlacesTaken).To(vm => vm.ParkingContent.PlacesTaken); set.Bind(lblPlacesTotal).To(vm => vm.ParkingContent.parkingStatus.totalCapacity); //Navigatiebaar vullen set.Bind(pbBaar).For(s => s.Progress).To(vm => vm.ParkingContent.Progress); //Gebied van de map waarop gefocust moet worden set.Bind(mpMap).For(s => s.Region).To(vm => vm.FocusRegion); //Annotatie op de map toevoegen // add an annotation: //set.Bind(mpMap).For(s => s.SelectedAnnotations).To(vm => vm.ParkingContent.MapAnnotation); mpMap.AddAnnotations(ViewModel.ParkingContent.MapAnnotation); #region ENKEL NODIG BIJ DEPLOYEN OP FYSIEKE IPHONE DOOR BUG //Map bij laden focussen op gebied: CLLocationCoordinate2D coords = new CLLocationCoordinate2D(ViewModel.ParkingContent.latitude, ViewModel.ParkingContent.longitude); MKCoordinateSpan span = new MKCoordinateSpan(0.01, 0.01); mpMap.Region = new MKCoordinateRegion(coords, span); #endregion set.Apply(); }
public void LoadMap() { try { MKPointAnnotation Annotation = new MKPointAnnotation(); CLLocationCoordinate2D AnnotationCoordinates = new CLLocationCoordinate2D(LocationLatitude, LocationLongitude); Annotation.Title = AnnotationTitle; Annotation.Coordinate = AnnotationCoordinates; MKMapViewBusinessLines.AddAnnotation(Annotation); CLLocationCoordinate2D LocationCoordinate = new CLLocationCoordinate2D(LocationLatitude, LocationLongitude); MKCoordinateSpan coordinateSpan = new MKCoordinateSpan(5, 5); MKCoordinateRegion coordinateRegion = new MKCoordinateRegion(LocationCoordinate, coordinateSpan); MKMapViewBusinessLines.SetRegion(coordinateRegion, true); } catch (Exception ex) { } }
private void PrepareMap(double lat, double lng) { try { CLLocationCoordinate2D coordsfordestinatin = new CLLocationCoordinate2D(lat, lng); MKCoordinateSpan span3 = new MKCoordinateSpan(StudentTracking.MilesToLatitudeDegrees(2), StudentTracking.MilesToLongitudeDegrees(2, coordsfordestinatin.Latitude)); mapview.Region = new MKCoordinateRegion(coordsfordestinatin, span3); // set the map delegate var mapDel = new MyMapDelegate(); mapview.Delegate = mapDel; // add a custom annotation mapview.AddAnnotation(new CustomAnnotation(0, StaticDataModel.StudentInfo + "'student location", coordsfordestinatin)); } catch (Exception ex) { } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. map = new MKMapView(UIScreen.MainScreen.Bounds); var coordinate = new CLLocationCoordinate2D(23.674764, 120.92); var span = new MKCoordinateSpan(3, 3); var region = new MKCoordinateRegion(coordinate, span); map.SetRegion(region, true); map.ZoomEnabled = false; map.ScrollEnabled = false; map.Delegate = new MyMapDelegate(this); View = map; GetMyMarkers(); }
public override void ViewDidLoad() { base.ViewDidLoad(); double x, y; x = 42.364260; y = -71.120824; // Perform any additional setup after loading the view, typically from a nib. Mapa.MapType = MKMapType.Standard; Mapa.AddAnnotation(new CustomAnnotation("Xamarin", new CLLocationCoordinate2D(x, y))); CLLocationCoordinate2D Centrar = new CLLocationCoordinate2D(x, y); MKCoordinateSpan Altura = new MKCoordinateSpan(.002, .002); MKCoordinateRegion Region = new MKCoordinateRegion(Centrar, Altura); Mapa.SetRegion(Region, true); }
private void LoadDataForMapRegionAndBikes() { var plist = NSDictionary.FromFile(NSBundle.MainBundle.PathForResource("Data", "plist")); var region = plist["region"] as NSArray; if (region != null) { var coordinate = new CLLocationCoordinate2D(region.GetItem <NSNumber>(0).NFloatValue, region.GetItem <NSNumber>(1).NFloatValue); var span = new MKCoordinateSpan(region.GetItem <NSNumber>(2).NFloatValue, region.GetItem <NSNumber>(3).NFloatValue); MapView.Region = new MKCoordinateRegion(coordinate, span); } var bikes = plist["bikes"] as NSArray; if (bikes != null) { MapView.AddAnnotations(Bike.FromDictionaryArray(bikes)); } }
private void SetUpMapView() { MapKitView = new MKMapView(); View = MapKitView; MapKitView.ZoomEnabled = true; MapKitView.ScrollEnabled = true; CLLocationManager locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); MapKitView.ShowsUserLocation = true; MapKitView.DidUpdateUserLocation += delegate { if (MapKitView.UserLocation != null) { CLLocationCoordinate2D coordinateUser = MapKitView.UserLocation.Coordinate; MKCoordinateSpan coordinateSpanUser = new MKCoordinateSpan(0.02, 0.02); MapKitView.Region = new MKCoordinateRegion(coordinateUser, coordinateSpanUser); } }; if (!MapKitView.UserLocationVisible) { CLLocationCoordinate2D coords = new CLLocationCoordinate2D(49.99181, 36.23572); MKCoordinateSpan span = new MKCoordinateSpan(0.05, 0.05); MapKitView.Region = new MKCoordinateRegion(coords, span); } var longGesture = new UILongPressGestureRecognizer(LongPress); longGesture.MinimumPressDuration = 0.5; MapKitView.AddGestureRecognizer(longGesture); MapKitView.GetViewForAnnotation += GetViewForAnnotation; if (ViewModel.LalitudeMarker != 0) { _lalitude = this.ViewModel.LalitudeMarker; _longitude = this.ViewModel.LongitudeMarker; MapKitView.AddAnnotations(new MKPointAnnotation() { Coordinate = new CLLocationCoordinate2D(_lalitude, _longitude) }); } }
private void PrepareMap() { // throw new NotImplementedException(); // boilerplate from ALT+ENTER on PrepareMap(); locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); deliverMapView.ShowsUserLocation = true; var span = new MKCoordinateSpan(0.15, 0.15); // 0.15 degrees of lat/lng coverage in span var coordinates = new CLLocationCoordinate2D(delivery.DestinationLatitude, delivery.DestinationLongitude); deliverMapView.Region = new MKCoordinateRegion(coordinates, span); deliverMapView.AddAnnotation(new MKPointAnnotation() { Coordinate = coordinates, Title = "Deliver here" // Coordinate and Title are standard members/fields for MKPointAnnotation }); }
async Task SearchAsync(string what, string where) { var coord = here == null?Parse(where) : here.Coordinate; MKCoordinateSpan span = new MKCoordinateSpan(0.25, 0.25); MKLocalSearchRequest request = new MKLocalSearchRequest(); request.Region = new MKCoordinateRegion(coord, span); request.NaturalLanguageQuery = what; MKLocalSearch search = new MKLocalSearch(request); MKLocalSearchResponse response; try{ response = await search.StartAsync(); } catch { return; } if (response == null) { return; } var section = new Section("Search Results for " + what); results.Clear(); foreach (MKMapItem mi in response.MapItems) { results.Add(mi); var element = new StyledStringElement(mi.Name, mi.PhoneNumber, UITableViewCellStyle.Subtitle); element.Accessory = UITableViewCellAccessory.DisclosureIndicator; element.Tapped += () => { results [element.IndexPath.Row].OpenInMaps(); }; section.Add(element); } var root = new RootElement("MapKit Search Sample") { section }; var dvc = new DialogViewController(root); (window.RootViewController as UINavigationController).PushViewController(dvc, true); }
//zoom public void ZoomIn() { //Zoom in // user location var userCoord = new CLLocationCoordinate2D { Latitude = _userLocation.Latitude, Longitude = _userLocation.Longitude }; // tracking location var trackCoord = new CLLocationCoordinate2D { Latitude = _trackCoordinate.Latitude, Longitude = _trackCoordinate.Longitude }; List <CLLocationCoordinate2D> annotations = new List <CLLocationCoordinate2D> (); annotations.Add(userCoord); annotations.Add(trackCoord); var tl = new CLLocationCoordinate2D(-90, 180); //top left var br = new CLLocationCoordinate2D(90, -180); //bottom right foreach (var anno in annotations) { tl.Longitude = Math.Min(tl.Longitude, anno.Longitude); tl.Latitude = Math.Max(tl.Latitude, anno.Latitude); br.Longitude = Math.Max(br.Longitude, anno.Longitude); br.Latitude = Math.Min(br.Latitude, anno.Latitude); } var center = new CLLocationCoordinate2D { Latitude = tl.Latitude - (tl.Latitude - br.Latitude) * 0.5, Longitude = tl.Longitude + (br.Longitude - tl.Longitude) * 0.5 }; var span = new MKCoordinateSpan { LatitudeDelta = Math.Abs(tl.Latitude - br.Latitude) * 1.6, LongitudeDelta = Math.Abs(br.Longitude - tl.Longitude) * 1.6 }; var region = new MKCoordinateRegion { Center = center, Span = span }; region = _mapView.RegionThatFits(region); _mapView.SetRegion(region, true); }
public void ShowUserAndDestinationOnMap() { var maxLat = Math.Max(_userLocation.Latitude, _destination.Latitude); var maxLon = Math.Max(_userLocation.Longitude, _destination.Longitude); var minLat = Math.Min(_userLocation.Latitude, _destination.Latitude); var minLon = Math.Min(_userLocation.Longitude, _destination.Longitude); var mapMargin = 1.5; var leastCoordspan = 0.005; var span_x = Math.Max(leastCoordspan, Math.Abs(maxLat - minLat) * mapMargin); var span_y = Math.Max(leastCoordspan, Math.Abs(maxLon - minLon) * mapMargin); var span = new MKCoordinateSpan(span_x, span_y); var center = new CLLocationCoordinate2D((maxLat + minLat) / 2, (maxLon + minLon) / 2); var region = new MKCoordinateRegion(center, span); _mapView.SetRegion(_mapView.RegionThatFits(region), true); }
private void SourceMapView_DidUpdateUserLocation(object sender, MapKit.MKUserLocationEventArgs e) { if (SourceMapView.UserLocation == null) { return; } var coordinates = SourceMapView.UserLocation.Coordinate; var span = new MKCoordinateSpan(0.15, 0.15); SourceMapView.Region = new MKCoordinateRegion(coordinates, span); SourceMapView.RemoveAnnotations(); SourceMapView.AddAnnotation(new MKPointAnnotation { Coordinate = coordinates, Title = "Your location" }); }
public void ShowCoffee(CoffeeShop coffee) { var coord = new CoreLocation.CLLocationCoordinate2D( coffee.Coordinates.Latitude, coffee.Coordinates.Longitude ); var annotation = new MKPointAnnotation { Title = coffee.Name, Coordinate = coord }; this.map.AddAnnotation(annotation); this.map.ShowAnnotations(new IMKAnnotation[] { annotation }, true); this.map.SelectAnnotation(annotation, true); var span = new MKCoordinateSpan(.01f, .01f); map.Region = new MKCoordinateRegion(coord, span); }
public void CenterInLocalisation(double latitude , double longitude , float zoomLevel , bool withAnimation = false) { var mapCenter = new CLLocationCoordinate2D(latitude, longitude); if (zoomLevel != 0) { var span = new MKCoordinateSpan(0, 360 / Math.Pow(2, zoomLevel) * MapViewControl.Frame.Size.Width / 256); var mapRegion = new MKCoordinateRegion(mapCenter, span); MapViewControl.CenterCoordinate = mapCenter; MapViewControl.SetRegion(mapRegion, withAnimation); } else { MapViewControl.CenterCoordinate = mapCenter; } }
protected override void OnElementChanged(ElementChangedEventArgs <Bugzilla39987.CustomMapView> e) { base.OnElementChanged(e); if (e.NewElement != null) { if (Control == null) { _mapView = new MKMapView(UIScreen.MainScreen.Bounds); _mapView.MapType = MKMapType.Standard; _mapView.RotateEnabled = false; SetNativeControl(_mapView); } } CLLocationCoordinate2D coords = new CLLocationCoordinate2D(48.857, 2.351); MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude)); _mapView.Region = new MKCoordinateRegion(coords, span); }
public override void ViewDidLoad () { base.ViewDidLoad (); Title = "Map of Paris!"; // create our location and zoom for paris CLLocationCoordinate2D coords = new CLLocationCoordinate2D(48.857, 2.351); MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coords.Latitude)); // set the coords and zoom on the map mapMain.Region = new MKCoordinateRegion(coords, span); // to animate to a location, then call SetRegion: //mapMain.SetRegion(coords, true); // to show the device location: //mapMain.ShowsUserLocation = true; // change the map type based on what's selected in the segment control sgmtMapType.ValueChanged += (s, e) => { switch(sgmtMapType.SelectedSegment) { case 0: mapMain.MapType = MKMapType.Standard; break; case 1: mapMain.MapType = MKMapType.Satellite; break; case 2: mapMain.MapType = MKMapType.Hybrid; break; } }; }
public override void ViewDidLoad() { base.ViewDidLoad (); if (AppModel != null && AppModel.SelectedProvider != null) { loadingOverlay = new LoadingOverlay (UIScreen.MainScreen.Bounds); View.Add (loadingOverlay); AppModel.CoordinatedUpdated += (e,a) => { this.BeginInvokeOnMainThread(delegate { loadingOverlay.Hide (); CLLocationCoordinate2D coords = new CLLocationCoordinate2D(AppModel.ProviderLocation.Latitude, AppModel.ProviderLocation.Longtitude); MKCoordinateSpan span = new MKCoordinateSpan(MilesToLatitudeDegrees(5), MilesToLongitudeDegrees(5, coords.Latitude)); map.Region = new MKCoordinateRegion(coords, span); var prompt = string.Format("Dr {0} {1}", AppModel.SelectedProvider.FirstName,AppModel.SelectedProvider.LastName); var annotation = new ProviderAnnotation (coords, prompt); map.AddAnnotation(annotation); }); }; AppModel.GetProviderLocation (); } }
private static void CenterOnAtlanta(MKMapView map) { MKCoordinateSpan span = new MKCoordinateSpan (MilesToLatitudeDegrees (250), MilesToLongitudeDegrees (250, Atlanta.Latitude)); map.Region = new MKCoordinateRegion (Atlanta.Coordinates, span); }
private void ShowMap() { UIApplication.SharedApplication.InvokeOnMainThread (delegate { StartUpdatingLocation(); IPhoneUIViewController contentController = new IPhoneUIViewController ("Map", "Back"); if (unityMapView == null) { unityMapView = new UnityMapView (); } coord = new CLLocationCoordinate2D (unityLocation.Latitude, unityLocation.Longitude); coordSpan = new MKCoordinateSpan (latitudeDeltaSpan, longitudeDeltaSpan); //0.5 means 0.5 degrees -> 55 km approximately; so it display an area of (55 Km * 55 Km) arround the current coordinates coordRegion = new MKCoordinateRegion (coord, coordSpan); setMapView (); setAnnotationPoints (); contentController.AddInnerView (unityMapView); IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().PresentModalViewController (contentController, true); IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false); }); }
static MKCoordinateRegion BuildVisibleRegion(CLLocationCoordinate2D currentLocation) { var span = new MKCoordinateSpan(5, 5); var region = new MKCoordinateRegion(currentLocation, span); return region; }
void HandleUpdatedLocation (CLLocation newLocation) { if (ignoreMapUpdate) return; if (newLocation == null) { if (localisationRetryCount == 0) { localisationRetryCount++; Action action = () => { Util.RequestLocation(HandleUpdatedLocation); }; Util.ShowAlertSheet("No reply from network! Give another try? :)", View, action); } else { localisationRetryCount++; Thread.Sleep(300); Util.RequestLocation(HandleUpdatedLocation); if (localisationRetryCount == 4) localisationRetryCount = 0; } } else { loaded = true; PhotoLocation = newLocation; var spanLocal = new MKCoordinateSpan (0.02, 0.02); var span = firstUpdate ? spanLocal : mapView.Region.Span; firstUpdate = false; var region = new MKCoordinateRegion (newLocation.Coordinate, span); mapView.SetRegion (region, false); mapView.SetCenterCoordinate (newLocation.Coordinate, false); //mapView.SelectAnnotation(mapView.UserLocation, false); double radiusInMeters = 100d; MKCircle circle = MKCircle.Circle(newLocation.Coordinate, radiusInMeters); mapView.AddOverlay(circle); RepositionAnnotation(newLocation.Coordinate); } }
void ShowCarParkOnMap() { var annotation = new MapAnnotation (new CLLocationCoordinate2D (_parking.Latitude, _parking.Longitude), _parking.Description, _parking.Address); mapView.AddAnnotation (annotation); var coords = new MonoTouch.CoreLocation.CLLocationCoordinate2D (_parking.Latitude, _parking.Longitude); var span = new MKCoordinateSpan (KilometresToLatitudeDegrees (0.5), KilometresToLongitudeDegrees (0.5, coords.Latitude)); mapView.Region = new MKCoordinateRegion (coords, span); }
/// <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); } }
protected void ZoomToShowAllPins(){ if(mapView.Annotations.Count() > 0) { var southWest = (mapView.Annotations.First() as MKAnnotation).Coordinate; var northEast = (mapView.Annotations.First() as MKAnnotation).Coordinate; //Calclulate bounds by looking at all annontations: foreach(var obj in mapView.Annotations){ if(obj is MKAnnotation) { MKAnnotation a = obj as MKAnnotation; southWest.Latitude = Math.Min(southWest.Latitude, a.Coordinate.Latitude); southWest.Longitude = Math.Min(southWest.Longitude, a.Coordinate.Longitude); northEast.Latitude = Math.Max(northEast.Latitude, a.Coordinate.Latitude); northEast.Longitude = Math.Max(northEast.Longitude, a.Coordinate.Longitude); } } var locSouthWest = new CLLocation(southWest.Latitude, southWest.Longitude); var locNorthEast = new CLLocation(northEast.Latitude, northEast.Longitude); var spanLatitudeDelta = Math.Abs(locNorthEast.Coordinate.Latitude - locSouthWest.Coordinate.Latitude) * 2; var spanLongitudeDelta = Math.Abs(locNorthEast.Coordinate.Longitude - locSouthWest.Coordinate.Longitude) * 2; var regionCenterLatitude = (southWest.Latitude + northEast.Latitude) / 2; var regionCenterLongitude = (southWest.Longitude + northEast.Longitude) / 2; var span = new MKCoordinateSpan(spanLatitudeDelta, spanLongitudeDelta); var regionCenter = new CLLocationCoordinate2D(regionCenterLatitude, regionCenterLongitude); var region = new MKCoordinateRegion(regionCenter, span); mapView.SetRegion(region, true); } }
public override void ViewDidLoad() { base.ViewDidLoad (); mapView = new MKMapView() { ShowsUserLocation = true }; labelDistance = new UILabel() { Frame = new RectangleF (0, 0, 320, 49), Lines = 2, BackgroundColor = UIColor.Black, TextColor = UIColor.White }; var segmentedControl = new UISegmentedControl(); var topOfSegement = View.Frame.Height - 120; segmentedControl.Frame = new RectangleF(20, topOfSegement, 282, 30); segmentedControl.InsertSegment("Map".GetText(), 0, false); segmentedControl.InsertSegment("Satellite".GetText(), 1, false); segmentedControl.InsertSegment("Hybrid".GetText(), 2, false); segmentedControl.SelectedSegment = 0; segmentedControl.ControlStyle = UISegmentedControlStyle.Bar; segmentedControl.TintColor = UIColor.DarkGray; segmentedControl.ValueChanged += delegate { if (segmentedControl.SelectedSegment == 0) mapView.MapType = MonoTouch.MapKit.MKMapType.Standard; else if (segmentedControl.SelectedSegment == 1) mapView.MapType = MonoTouch.MapKit.MKMapType.Satellite; else if (segmentedControl.SelectedSegment == 2) mapView.MapType = MonoTouch.MapKit.MKMapType.Hybrid; }; mapView.Delegate = new MapViewDelegate(this); // Set the web view to fit the width of the app. mapView.SizeToFit(); // Reposition and resize the receiver mapView.Frame = new RectangleF (0, 50, View.Frame.Width, View.Frame.Height - 100); MKCoordinateSpan span = new MKCoordinateSpan(0.01,0.01); MKCoordinateRegion region = new MKCoordinateRegion(ConferenceLocation,span); mapView.SetRegion(region, true); ConferenceAnnotation a = new ConferenceAnnotation(ConferenceLocation , "CodeCampSDQ" , "INTEC" ); mapView.AddAnnotationObject(a); locationManager = new CLLocationManager(); locationManager.Delegate = new LocationManagerDelegate(mapView, this); locationManager.StartUpdatingLocation(); // Add the table view as a subview View.AddSubview(mapView); View.AddSubview(labelDistance); View.AddSubview(segmentedControl); // Add the 'info' button to flip var flipButton = UIButton.FromType(UIButtonType.InfoLight); flipButton.Frame = new RectangleF(290,17,20,20); flipButton.Title (UIControlState.Normal); flipButton.TouchDown += delegate { _mfvc.Flip(); }; View.AddSubview(flipButton); }
public override void ViewDidLoad() { base.ViewDidLoad (); mapView = new MKMapView() { ShowsUserLocation = true }; labelDistance = new UILabel() { Frame = new RectangleF (0, 0, 320, 49), Lines = 2, BackgroundColor = UIColor.Black, TextColor = UIColor.White }; var segmentedControl = new UISegmentedControl(); var topOfSegement = View.Frame.Height - 120; segmentedControl.Frame = new RectangleF(20, topOfSegement, 282, 30); 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(UIDevice.CurrentDevice.CheckSystemVersion(6,0)) segmentedControl.InsertSegment ("Directions", 3, false); segmentedControl.ValueChanged += delegate { if (segmentedControl.SelectedSegment == 0) mapView.MapType = MonoTouch.MapKit.MKMapType.Standard; else if (segmentedControl.SelectedSegment == 1) mapView.MapType = MonoTouch.MapKit.MKMapType.Satellite; else if (segmentedControl.SelectedSegment == 2) mapView.MapType = MonoTouch.MapKit.MKMapType.Hybrid; else if (segmentedControl.SelectedSegment == 3) { var conferenceMapItem = new MKMapItem(new MKPlacemark(ConferenceLocation, null)); conferenceMapItem.Name = "MonkeySpace"; var conferenceHotel = new MKMapItem(new MKPlacemark(new CLLocationCoordinate2D(42.36346, -71.0863), null)); conferenceHotel.Name = "MonkeySpace Hotel"; var mapItems = new MKMapItem[] { conferenceMapItem, conferenceHotel }; MKMapItem.OpenMaps(mapItems, new MKLaunchOptions() { DirectionsMode = MKDirectionsMode.Walking }); } }; mapView.Delegate = new MapViewDelegate(this); // Set the web view to fit the width of the app. mapView.SizeToFit(); // Reposition and resize the receiver mapView.Frame = new RectangleF (0, 50, View.Frame.Width, View.Frame.Height - 100); MKCoordinateSpan span = new MKCoordinateSpan(0.01,0.01); MKCoordinateRegion region = new MKCoordinateRegion(ConferenceLocation,span); mapView.SetRegion(region, true); ConferenceAnnotation a = new ConferenceAnnotation(ConferenceLocation , "MonkeySpace" , "NERD Center" ); mapView.AddAnnotationObject(a); locationManager = new CLLocationManager(); locationManager.Delegate = new LocationManagerDelegate(mapView, this); locationManager.StartUpdatingLocation(); // Add the table view as a subview View.AddSubview(mapView); View.AddSubview(labelDistance); View.AddSubview(segmentedControl); // Add the 'info' button to flip var flipButton = UIButton.FromType(UIButtonType.InfoLight); flipButton.Frame = new RectangleF(290,17,20,20); flipButton.Title (UIControlState.Normal); flipButton.TouchDown += delegate { _mfvc.Flip(); }; View.AddSubview(flipButton); }
public void SetLocation(CLLocation newLocation, string title, string description) { if(_mapview.Annotations.Contains(CurrentAnnotation)) { _mapview.RemoveAnnotation(CurrentAnnotation); } MKCoordinateSpan span = new MKCoordinateSpan(0.010, 0.010); MKCoordinateRegion region = new MKCoordinateRegion(newLocation.Coordinate, span); _mapview.SetRegion(region, true); if(CurrentAnnotation == null) CurrentAnnotation = new MyAnnotation(new CLLocationCoordinate2D(newLocation.Coordinate.Latitude, newLocation.Coordinate.Longitude), title, description); else { CurrentAnnotation.Coordinate = newLocation.Coordinate; } _mapview.AddAnnotation(CurrentAnnotation); _mapview.SelectAnnotation(CurrentAnnotation, false); }
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); }
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); } }