private void LoadData()
        {
            var jsonPath = NSBundle.MainBundle.PathForResource("Berlin-Data", "json");
            var inputStream = NSInputStream.FromFile(jsonPath);
            inputStream.Open();
            NSError err = null;
            var json = NSJsonSerialization.Deserialize(inputStream, 0, out err) as NSArray;

            MKPointAnnotation annotation = null;
            List<MKPointAnnotation> annotations = new List<MKPointAnnotation>();
            NSNumber lat = null;
            NSNumber lng = null;
            NSDictionary annotationAsJSON = null;

            for (int i = 0; i < json.Count; i++)
            {
                annotationAsJSON = json.GetItem<NSDictionary>(i);
                annotation = new MKPointAnnotation();
                lat = annotationAsJSON.ValueForKeyPath(new NSString("location.coordinates.latitude")) as NSNumber;
                lng = annotationAsJSON.ValueForKeyPath(new NSString("location.coordinates.longitude")) as NSNumber;
                annotation.Coordinate = new CLLocationCoordinate2D(lat.DoubleValue, lng.DoubleValue);
                annotation.Title = annotationAsJSON.ValueForKeyPath(new NSString("person.lastName")).ToString();
                annotations.Add(annotation);
            }

            _mapClusterController.AddAnnotations(annotations.ToArray(), null);
        }
		string GetIdentifier(MKPointAnnotation annotation)
		{
			Position annotationPosition = new Position (annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
			foreach (var pin in _pins) {
				if (pin.FormsPin.Position == annotationPosition)
					return pin.Identifier;	
			}
			return "";
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			// get access
			locationManager = new CLLocationManager ();
			locationManager.RequestWhenInUseAuthorization ();

			// create the annotation
			var sdAnnotation = new MKPointAnnotation {
				Title = "SDWebImage Annotation",
			};

			// create the view
			string pId = "sdwebimage";
			mapView.GetViewForAnnotation = (mapView, annotation) => {
				if (annotation is MKUserLocation)
					return null;

				// create annotation view
				var pinView = mapView.DequeueReusableAnnotation (pId);
				if (pinView == null) {
					pinView = new MKAnnotationView (annotation, pId);

					// get the image
					pinView.SetImage (
						new NSUrl ("http://radiotray.sourceforge.net/radio.png"),
						UIImage.FromBundle ("placeholder.png"),
						(image, error, cacheType, imageUrl) => {
							if (error != null) {
								Console.WriteLine ("Error: " + error);
							} else {
								Console.WriteLine ("Done: " + pinView.GetImageUrl ());
							}
						});
				}

				return pinView;
			};

			// add the annotation
			mapView.AddAnnotation (sdAnnotation);

			// move it
			mapView.DidUpdateUserLocation += (sender, e) => {
				var loc = e.UserLocation.Coordinate;
				sdAnnotation.Coordinate = new CLLocationCoordinate2D (loc.Latitude, loc.Longitude);

				mapView.SetCenterCoordinate (sdAnnotation.Coordinate, true);
			};

			// start tracking
			mapView.ShowsUserLocation = true;
		}
 CustomPin GetCustomPin(MKPointAnnotation annotation)
 {
     var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
       foreach (var pin in customPins)
       {
     if (pin.Pin.Position == position)
     {
       return pin;
     }
       }
       return null;
 }
		void OnLocationsUpdated (object sender, CLLocationsUpdatedEventArgs e)
		{
			currentLocation = e.Locations.LastOrDefault ();

			if (pin != null)
				return;

			pin = new MKPointAnnotation ();
			pin.SetCoordinate (currentLocation.Coordinate);

			map.AddAnnotation (pin);
			map.ShowAnnotations (new [] { pin }, false);

			locationManager.StopUpdatingLocation ();
		}
        void FindCentersForDiseaseControl()
        {
            var point = new MKPointAnnotation {
                Coordinate = new CLLocationCoordinate2D (CDC.Latitude, CDC.Longitude),
                Title = "Centers for Disease Control",
                Subtitle = "Zombie Outbreak"
            };

            map.AddAnnotation (point);

            //TODO : Demo 2 - Step 2 - Customize view
            //ColorCentersForDiseaseControlGreen ();

            Helpers.CenterOnCDC (map);
        }
Example #7
0
            public override void LocationsUpdated(CLLocationManager manager, CLLocation[] locations)
            {
                var destLocAnnotation = new MKPointAnnotation();

                destLocAnnotation.Coordinate = _destination;
                destLocAnnotation.Title      = "目的地";
                _mapView.AddAnnotation(destLocAnnotation);

                _userLocation = new CLLocationCoordinate2D(manager.Location.Coordinate.Latitude, manager.Location.Coordinate.Longitude);
                var userLocAnnotation = new MKPointAnnotation();

                userLocAnnotation.Coordinate = _userLocation;
                userLocAnnotation.Title      = "現在地";
                _mapView.AddAnnotation(userLocAnnotation);

                GetRoute();
                ShowUserAndDestinationOnMap();
            }
Example #8
0
        public void DidFinishRenderingMap(MKMapView mapView, bool fullyRendered)
        {
            mapView.RemoveAnnotations(mapView.Annotations);

            foreach (var city in Cities)
            {
                var location = new CLLocationCoordinate2D(latitude: city.Latitude,
                                                          longitude: city.Longitude);

                var pointAnnotation = new MKPointAnnotation
                {
                    Coordinate = location,
                    Title      = city.Title
                };

                mapView.AddAnnotation(pointAnnotation);
            }
        }
        private CustomPin GetCustomPin(MKPointAnnotation annotation)
        {
            if (annotation == null)
            {
                return(null);
            }

            var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);

            foreach (var pin in _customPins)
            {
                if (pin.Position == position)
                {
                    return(pin);
                }
            }
            return(null);
        }
Example #10
0
        private void UpdatePins()
        {
            if (_nativeMap == null)
            {
                return;
            }

            foreach (var p in _customMap.CustomPins)
            {
                MKPointAnnotation pa = new MKPointAnnotation
                {
                    Coordinate = new CoreLocation.CLLocationCoordinate2D(p.Pin.Position.Latitude, p.Pin.Position.Longitude),
                    Subtitle   = p.Pin.Address,
                    Title      = p.Pin.Label,
                };
                _nativeMap.AddAnnotation(pa);
            }
        }
Example #11
0
        CustomPin GetCustomPin(MKPointAnnotation annotation)
        {
            Position key = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);

            //Search Donor Pins
            if (customPins.TryGetValue(key, out CustomPin foundPin))
            {
                return(foundPin);
            }
            //Console.WriteLine(annotation.Subtitle);
            // Search helicopter pins
            helicopterPins = formsMap.HelicopterPins;
            if (helicopterPins.TryGetValue(annotation.Subtitle, out foundPin))
            {
                return(foundPin);
            }
            return(null);
        }
        ILocation GetCustomPin(MKPointAnnotation annotation)
        {
            var element = (ExtendedMap)Element;

            if (element.ItemsSource != null && annotation != null)
            {
                foreach (var pin in element.ItemsSource)
                {
                    if (pin.Latitude == annotation.Coordinate.Latitude &&
                        pin.Longitude == annotation.Coordinate.Longitude)
                    {
                        return(pin);
                    }
                }
            }

            return(null);
        }
Example #13
0
 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)
     {
     }
 }
        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 == "")
            {
                annotationView = new CustomMKPinAnnotationView(annotation, identifier);

                //annotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
                ((CustomMKPinAnnotationView)annotationView).PinColor        = MKPinAnnotationColor.Red;
                ((CustomMKPinAnnotationView)annotationView).FormsIdentifier = identifier;
                ((CustomMKPinAnnotationView)annotationView).AnimatesDrop    = true;
                annotationView.CanShowCallout = true;
                //throw new Exception("No Identifier found for pin");
            }
            else
            {
                annotationView = mapView.DequeueReusableAnnotation(identifier);
                if (annotationView == null)
                {
                    annotationView = new CustomMKPinAnnotationView(annotation, identifier);

                    //annotationView.LeftCalloutAccessoryView = new UIImageView(UIImage.LoadFromData("http://dpark.us/wp-content/uploads/2014/09/image1-125x125.jpg"));
                    annotationView.RightCalloutAccessoryView                    = UIButton.FromType(UIButtonType.DetailDisclosure);
                    ((CustomMKPinAnnotationView)annotationView).PinColor        = MKPinAnnotationColor.Green;
                    ((CustomMKPinAnnotationView)annotationView).FormsIdentifier = identifier;
                    ((CustomMKPinAnnotationView)annotationView).AnimatesDrop    = true;
                    annotationView.CanShowCallout = true;
                }
            }
            return(annotationView);
        }
        //CODE FOR GETTING DIRECTIONS
        public void getDirections(CLLocationCoordinate2D source, CLLocationCoordinate2D destination)
        {
//			var gg = new CLLocationCoordinate2D(37.8197, -122.4786);
//			var sfo = new CLLocationCoordinate2D(37.6189, -122.3750);
            var ggAnnotation = new MKPointAnnotation()
            {
                Title = "Starting Point", Coordinate = source
            };
            var sfoAnnotation = new MKPointAnnotation()
            {
                Title = "My Car", Coordinate = destination
            };

            ParkingMap.ShowAnnotations(new MKPointAnnotation[] { ggAnnotation, sfoAnnotation }, false);

            var emptyDict = new NSDictionary();
            var req       = new MKDirectionsRequest()
            {
                Source        = new MKMapItem(new MKPlacemark(source, emptyDict)),
                Destination   = new MKMapItem(new MKPlacemark(destination, emptyDict)),
                TransportType = MKDirectionsTransportType.Automobile
            };

            var dir = new MKDirections(req);

            dir.CalculateDirections((response, error) => {
                if (error == null)
                {
                    var route   = response.Routes[0];
                    var rteLine = new MKPolylineRenderer(route.Polyline)
                    {
                        LineWidth   = 5.0f,
                        StrokeColor = UIColor.Purple
                    };

                    ParkingMap.OverlayRenderer = (mv, ol) => rteLine;
                    ParkingMap.AddOverlay(route.Polyline, MKOverlayLevel.AboveRoads);
                }
                else
                {
                    Console.WriteLine(error);
                }
            });
        }
Example #16
0
        void showLocationOnMap()
        {
            CoreUtilities.GetLogService().Log(nameof(ExpenseDetailController.showLocationOnMap));
            var annotation   = new MKPointAnnotation();
            var coordination = new CLLocationCoordinate2D(_expense.Latitude, _expense.Longitude);

            annotation.Coordinate = coordination;
            ExpenseDetail_Map.RemoveAnnotations((ExpenseDetail_Map.Annotations));
            ExpenseDetail_Map.AddAnnotation(annotation);

            var region = new MKCoordinateRegion();

            region.Center.Latitude     = coordination.Latitude;
            region.Center.Longitude    = coordination.Longitude;
            region.Span.LatitudeDelta  = 0.01;
            region.Span.LongitudeDelta = 0.01;

            ExpenseDetail_Map.SetRegion(region, true);
        }
        void OnMapLongPress()
        {
            if (longPressGestureRecognizer.State != UIGestureRecognizerState.Began)
            {
                return;
            }

            CGPoint pixelLocation             = longPressGestureRecognizer.LocationInView(NativeMapView);
            CLLocationCoordinate2D coordinate = NativeMapView.ConvertPoint(pixelLocation, NativeMapView);

            //add map annotation
            MKPointAnnotation annotation = new MKPointAnnotation();

            annotation.Coordinate = coordinate;
            annotation.Title      = string.Format("{0},{1}", coordinate.Latitude, coordinate.Longitude);

            NativeMapView.AddAnnotation(annotation);
            annotationsList.Add(annotation);
        }
Example #18
0
        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);
        }
        string GetIdentifier(MKPointAnnotation annotation)
        {
            try
            {
                var      formsMap           = (CustomMap)Element;
                Position annotationPosition = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);

                foreach (var item in formsMap.CustomPins)
                {
                    if (item.Pin.Position == annotationPosition)
                    {
                        return(item.Id);
                    }
                }
            }
            catch { return(""); }

            return("");
        }
        public override void Refresh(ChallengeResponseModel challengeResponce)
        {
            base.Refresh(challengeResponce);

            if (challengeResponce == null)
            {
                return;
            }

            Challenge      = challengeResponce.Challenge;
            HeaderLbl.Text = Challenge.Name;
            //MainTextLable.Text = Challenge.Desc;
            TimeDisLbl.Text = Challenge.NextEventCountDown;

            var navigationDelegate = new ChallengeDetailWebViewNavigationDelegate();

            navigationDelegate.NavigationFinished += SetupConstraint;
            this.WebView.NavigationDelegate        = navigationDelegate;
            WebView.LoadHtmlString(Challenge.Desc, null);

            if (!DidSetupMap && Challenge.LocationLat != null && Challenge.LocationLong != null)
            {
                double radius = Challenge.RadiusMeters ?? 100.0;
                if (radius > 6000000)
                {
                    radius = 6000000;
                }
                double mapRegion = radius * 2.5;

                CLLocationCoordinate2D mapCoordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapView.SetRegion(MKCoordinateRegion.FromDistance(mapCoordinate, mapRegion, mapRegion), true);

                MKCircle circle = MKCircle.Circle(mapCoordinate, radius);
                MapView.AddOverlay(circle);

                MKPointAnnotation annotation = new MKPointAnnotation();
                annotation.Coordinate = new CLLocationCoordinate2D(Challenge.LocationLat.Value, Challenge.LocationLong.Value);
                MapView.AddAnnotation(annotation);

                DidSetupMap = true;
            }
        }
 /// <summary>
 /// Gets a custom pin from the maps custom pin list so the renderer can use it's custom properties.
 /// </summary>
 /// <param name="annotation"></param>
 /// <returns>Returns a custom pin which can be used to setup up the maps annotations.</returns>
 CustomPin GetCustomPin(MKPointAnnotation annotation)
 {
     if (annotation != null)
     {
         /*TE: Look through the events and return the pin whose coordinates match the coordinates of the pin clicked on.*/
         foreach (CustomPin pin in customPins)
         {
             /*TE: If positions match we return the pin.*/
             if (pin.Position.Latitude == annotation.Coordinate.Latitude && pin.Position.Longitude == annotation.Coordinate.Longitude)
             {
                 return(pin);
             }
         }
         return(null);
     }
     else
     {
         return(null);
     }
 }
        private void UpdatePins()
        {
            var mkMapView = Control;
            var formsMap  = Element;
            var items     = formsMap.Pins;

            foreach (var item in items)
            {
                var coord = new CLLocationCoordinate2D(item.Position.Latitude, item.Position.Longitude);

                var point = new MKPointAnnotation()
                {
                    Title = item.Label
                };

                point.SetCoordinate(coord);

                mkMapView.AddAnnotation(point);
            }
        }
Example #23
0
File: vcMap.cs Project: pauZc/8_iOS
        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);
        }
Example #24
0
 SupportMapPin GetCustomPin(MKPointAnnotation annotation)
 {
     try
     {
         var position = new Position(annotation.Coordinate.Latitude, annotation.Coordinate.Longitude);
         foreach (var pin in supportMapView.SupportPins)
         {
             if (pin.Position.Latitude.ToString().Equals(position.Latitude.ToString()) &&
                 pin.Position.Longitude.ToString().Equals(position.Longitude.ToString()))
             {
                 return(pin);
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.StackTrace);
     }
     return(null);
 }
        void CalculateRouteFromUserLocation(object sender, EventArgs e)
        {
            CLLocationCoordinate2D destinationLocation  = new CLLocationCoordinate2D(CustomMapView.RouteDestination.Latitude, CustomMapView.RouteDestination.Longitude);
            MKPlacemark            destinationPlacemark = new MKPlacemark(coordinate: destinationLocation);

            sourceMapItem      = MKMapItem.MapItemForCurrentLocation();
            destinationMapItem = new MKMapItem(destinationPlacemark);

            MKPointAnnotation destinationAnnotation = new MKPointAnnotation();

            //destinationAnnotation.Title = "Destination";
            destinationAnnotation.Coordinate = destinationPlacemark.Location.Coordinate;

            //save annotations so they can be removed later if requested
            annotationsList.Add(destinationAnnotation);

            NativeMapView.AddAnnotation(destinationAnnotation);

            CalculateRouteDetails();
        }
        private void AnnotationHandler(CLPlacemark[] placemarks, NSError error)
        {
            if (error != null)
            {
                Console.WriteLine(error.LocalizedDescription);
            }

            if (placemarks != null)
            {
                var placemark  = placemarks[0];
                var annotation = new MKPointAnnotation();
                var location   = placemark.Location;
                if (location != null)
                {
                    annotation.Coordinate = location.Coordinate;
                    MapView.AddAnnotation(annotation);
                    var region = MKCoordinateRegion.FromDistance(annotation.Coordinate, 250, 250);
                    MapView.SetRegion(region, false);
                }
            }
        }
Example #27
0
        public void MapInit()
        {
            MapServices.ProvideAPIKey(MapsApiKey);

            //myMapView = new MKMapView(UIScreen.MainScreen.Bounds);
            myMapView.ZoomEnabled   = true;
            myMapView.ScrollEnabled = true;

            myMapView.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            CLLocationCoordinate2D coords = new CLLocationCoordinate2D(26.2402577, 127.685999);
            MKCoordinateSpan       span   = new MKCoordinateSpan(KilometresToLatitudeDegrees(130), KilometresToLongitudeDegrees(130, coords.Latitude));

            myMapView.Region = new MKCoordinateRegion(coords, span);

            MKPointAnnotation perthAnno = new MKPointAnnotation();

            perthAnno.Title      = "Dojo";
            perthAnno.Subtitle   = "Aja 264 Naha";
            perthAnno.Coordinate = new CLLocationCoordinate2D(26.2402577, 127.685999);

            myMapView.AddAnnotation(perthAnno);
        }
Example #28
0
        private CustomPin GetCustomPin(MKPointAnnotation annotation)
        {
            if (annotation == null)
            {
                return(null);
            }

            var position = new Gps()
            {
                Latitude  = annotation.Coordinate.Latitude,
                Longitude = annotation.Coordinate.Longitude
            };

            foreach (var pin in customPins)
            {
                if (pin.Location.Equals(position))
                {
                    return(pin);
                }
            }
            return(null);
        }
        // Dictionary<Location, IMKAnnotation> _annotationsMap = new Dictionary<Location, IMKAnnotation> ();
        // Dictionary<Location, IMKOverlay> _overlaysMap = Dictionary<Location, IMKOverlay> ();
        void ShowLocationsInMap()
        {
            var locations = _repository.FetchAll ();

            foreach (var l in locations)
            {
                _logger.Info (string.Format ("MapViewController: Adding visuals for '{0}'", l.Name));

                var annotation = new MKPointAnnotation
                {
                    Title = l.Name,
                    Coordinate = new CLLocationCoordinate2D (l.Region.Latitude, l.Region.Longitude)
                };

                _mapView.AddAnnotation (annotation);
                // _annotationsMap.Add (l, annotation);

                var circleOverlay = MKCircle.Circle (annotation.Coordinate, l.Region.AlertZoneRadiusInMeters);
                _mapView.AddOverlay (circleOverlay);
                // _overlaysMap.Add (l, circleOverlay);
            }
        }
Example #30
0
        private void AnnotationHandler(CLPlacemark[] placemarks, NSError error)
        {
            if (error != null)
            {
                Console.WriteLine(error);
            }

            if (placemarks != null)
            {
                var placemark  = placemarks[0];
                var annotation = new MKPointAnnotation();
                annotation.Title    = RestaurantMO.Name;
                annotation.Subtitle = RestaurantMO.Type;
                var location = placemark.Location;
                if (location != null)
                {
                    annotation.Coordinate = location.Coordinate;
                    MapView.ShowAnnotations(new[] { annotation }, true);
                    MapView.SelectAnnotation(annotation, true);
                }
            }
        }
Example #31
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            //Map_Map.MapType = MapKit.MKMapType.Standard;

            if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            {
                m_LocationManager.RequestWhenInUseAuthorization();
            }
            Map_Map.ShowsUserLocation = true;
            MKPointAnnotation oPointAnnotation = new MKPointAnnotation
            {
                Title = "¸Î¶©¹q¯à",
            };

            oPointAnnotation.SetCoordinate(new CLLocationCoordinate2D(24.977109, 121.545983));
            Map_Map.AddAnnotation(oPointAnnotation);
            Map_Map.GetViewForAnnotation = delegate(MKMapView mapView, IMKAnnotation annotation)
            {
                if (annotation is MKPointAnnotation)
                {
                    MKPinAnnotationView pinAnnotationView = (MKPinAnnotationView)Map_Map.DequeueReusableAnnotation(m_PointAnnotationId);
                    if (pinAnnotationView == null)
                    {
                        pinAnnotationView                           = new MKPinAnnotationView(annotation, m_PointAnnotationId);
                        pinAnnotationView.PinColor                  = MKPinAnnotationColor.Purple;
                        pinAnnotationView.CanShowCallout            = true;
                        pinAnnotationView.RightCalloutAccessoryView = UIButton.FromType(UIButtonType.DetailDisclosure);
                    }
                    return(pinAnnotationView);
                }
                return(null);
            };


            //Map_Map.SetUserTrackingMode(MKUserTrackingMode.None, true);
            Map_Map.ShowAnnotations(new IMKAnnotation[] { oPointAnnotation }, true);
        }
Example #32
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            Branch b = ApplicationData.Current.HomeBranch;

            if (b != null)
            {
                BranchNumberLabel.Text = b.Number;
                BranchNameLabel.Text   = b.Name;
                StreetLabel.Text       = b.Street1;
                CityLabel.Text         = $"{b.City}, {b.Province} {b.PostalCode}";
                PhoneLabel.Text        = b.PhoneNumber;
                FaxLabel.Text          = b.FaxNumber;
                MKPointAnnotation point = new MKPointAnnotation()
                {
                    Title      = b.Name,
                    Subtitle   = $"{b.Street1} {b.City}",
                    Coordinate = new CoreLocation.CLLocationCoordinate2D(b.Latitude, b.Longitude)
                };
                Map.AddAnnotation(point);
                Map.ShowAnnotations(Map.Annotations, true);
            }
        }
        private void CreateNewAnnotations(IEnumerable <DropPin> pinsToAdd)
        {
            if (pinsToAdd == null)
            {
                return;
            }

            foreach (var dropPin in pinsToAdd)
            {
                var pin         = dropPin.Pin;
                var geoPosition = new CLLocationCoordinate2D()
                {
                    Latitude = pin.Position.Latitude, Longitude = pin.Position.Longitude
                };
                var mapAnnotation = new MKPointAnnotation {
                    Coordinate = geoPosition, Title = pin.Label, Subtitle = pin.Address
                };

                dropPin.PlatformMarker = mapAnnotation;
                _nativeMap?.AddAnnotation(mapAnnotation);

                pin.PropertyChanged += PinPropertyChanged;
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            rayMap = new MKMapView(View.Bounds);
            rayMap.AutoresizingMask = UIViewAutoresizing.FlexibleDimensions;
            rayMap.MapType          = MKMapType.Standard;
            View.AddSubview(rayMap);
            double latitude   = 40.7540577;
            double longitude  = -73.9837790;
            var    rayPlace   = new CLLocationCoordinate2D(latitude, longitude);
            var    zoomRegion = MKCoordinateRegion.FromDistance(rayPlace, 2000, 2000);

            rayMap.CenterCoordinate = rayPlace;
            rayMap.Region           = zoomRegion;
            lm.RequestWhenInUseAuthorization();
            rayMap.ShowsUserLocation = true;
            var RayAnno = new MKPointAnnotation()
            {
                Title      = "Ray Hot Dog",
                Coordinate = rayPlace
            };

            rayMap.AddAnnotation(RayAnno);
        }
Example #35
0
        private async void SubmitButton_TouchDown(object sender, EventArgs e)
        {
            try
            {
                Debug.WriteLine(sender.GetType().Name);
                mapping.returnedChoice = picker.SelectedName;

                var item = new Item
                {
                    Name      = picker.SelectedName,
                    Latitude  = mapping.GetLocation.Latitude,
                    Longitude = mapping.GetLocation.Longitude,
                    Id        = Guid.NewGuid().ToString(),
                    Date      = DateTime.Now
                };
                var result = await dataStore.AddItemAsync(item, picker.SelectedName.ToLowerInvariant(), picker.SelectedItem.Id);

                if (!(result.Equals(HttpStatusCode.Accepted)) || !(result.Equals(HttpStatusCode.OK)) || !(result.Equals(HttpStatusCode.Processing)))
                {
                    Debug.WriteLine($"Status code returned with {result}");
                    //return;
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
            }
            var annotation = new MKPointAnnotation
            {
                Coordinate = mapping.GetLocation,
                Title      = picker.SelectedName
            };

            mapping.GetMap.AddAnnotation(annotation);
            DismissViewController(true, null);
        }
        void SearchLocal(object sender, EventArgs e)
        {
            MKLocalSearchRequest request = new MKLocalSearchRequest();

            request.NaturalLanguageQuery = CustomMapView.SearchText;
            request.Region = NativeMapView.Region;

            MKLocalSearch search = new MKLocalSearch(request);

            search.Start((MKLocalSearchResponse response, Foundation.NSError error) =>
            {
                if (error != null)
                {
                    System.Diagnostics.Debug.WriteLine(error.Description);
                }
                else if (response.MapItems.Length == 0)
                {
                    System.Diagnostics.Debug.WriteLine("No matches found for search: " + CustomMapView.SearchText);
                }
                else
                {
                    ClearRoute(null, null);

                    foreach (MKMapItem mapItem in response.MapItems)
                    {
                        MKPointAnnotation annotation = new MKPointAnnotation();
                        annotation.Coordinate        = mapItem.Placemark.Coordinate;
                        annotation.Title             = mapItem.Name;

                        annotationsList.Add(annotation);
                    }

                    NativeMapView.ShowAnnotations(annotationsList.ToArray(), true);
                }
            });
        }
Example #37
0
        private CustomPin GetCustomPin(MKPointAnnotation pointAnnotation)
        {
            var position = new Position(pointAnnotation.Coordinate.Latitude, pointAnnotation.Coordinate.Longitude);

            foreach (var customPin in _customMap.CustomPins)
            {
                if (customPin.Pin.Position != position)
                {
                    continue;
                }
                if (string.IsNullOrEmpty(customPin.Pin.Label))
                {
                    continue;
                }
                if (customPin.Pin.Label != pointAnnotation.Title)
                {
                    continue;
                }

                return(customPin);
            }

            return(null);
        }
Example #38
0
		void AddPins(IList pins)
		{
			foreach (Pin pin in pins)
			{
				var annotation = new MKPointAnnotation { Title = pin.Label, Subtitle = pin.Address ?? "" };

				pin.Id = annotation;
#if __UNIFIED__
				annotation.SetCoordinate(new CLLocationCoordinate2D(pin.Position.Latitude, pin.Position.Longitude));
#else
				annotation.Coordinate = new CLLocationCoordinate2D (pin.Position.Latitude, pin.Position.Longitude);
#endif
				((MKMapView)Control).AddAnnotation(annotation);
			}
		}
Example #39
0
        void AnnotateMapWithLagerName(Lager myLager,double latitude, double longitude)
        {
            if (myLager.Name != null) {
                LagerAnnotation = new MKPointAnnotation () {
                    Title = myLager.Name,
                    Coordinate = new CLLocationCoordinate2D (latitude, longitude),
                };

                mapView.AddAnnotation (LagerAnnotation);
            }
        }
        private void InitializeMap()
        {
            locationManager = new CLLocationManager ();

            if (UIDevice.CurrentDevice.CheckSystemVersion (8, 0)) {
                locationManager.RequestWhenInUseAuthorization ();
            }

            map = new MKMapView (UIScreen.MainScreen.Bounds);
            View.Add (map);

            if (CLLocationManager.LocationServicesEnabled) {
                map.ShowsUserLocation = true;
            }

            var centersForDiseaseControlAnnotation = new MKPointAnnotation {
                Coordinate = new CLLocationCoordinate2D (CDC.Latitude, CDC.Longitude),
                Title = "Centers for Disease Control",
                Subtitle = "Zombie Outbreak"
            };
            map.AddAnnotation (centersForDiseaseControlAnnotation);
            Helpers.CenterOnAtlanta (map);
        }
        /// <summary>
        /// Purpose: Draw the first placemark in the mapview with the person name and street -> zoom the camera at the location
        /// </summary>
        /// <param name="placemarks">Placemarks.</param>
        /// <param name="error">Error.</param>
        void HandleCLGeocodeCompletionHandler (CLPlacemark[] placemarks, NSError error)
        {

            CLLocationCoordinate2D loc;

            // if GeoCode hasn't found a placemark, leave the function
            if (placemarks == null)
                return;

            // Delete the previous annotation
            if (_MainAnnotation != null)
                MapView.RemoveAnnotation(_MainAnnotation);

            // Assign the class annotation with the received values
            loc = placemarks[0].Location.Coordinate;

            _MainAnnotation =  new MKPointAnnotation(){ Title = _person.Name ,Subtitle = _person.Strasse  
            };
            _MainAnnotation.SetCoordinate(new CLLocationCoordinate2D (loc.Latitude,loc.Longitude ));
               
            // Add the annotation to the mapview
            MapView.AddAnnotation(_MainAnnotation);

            var region = new MKCoordinateRegion (_MainAnnotation.Coordinate,new MKCoordinateSpan (1f / 0.5f, 1f /  0.5f));
            //          
            MapView.SetRegion (region, true);


           
        }
 private void UpdateUiCoords()
 {
     CurrentLatitude.Text = _iPhoneLocationManager.Location.Coordinate.Latitude.ToString(CultureInfo.InvariantCulture);
     CurrentLongitude.Text = _iPhoneLocationManager.Location.Coordinate.Longitude.ToString(CultureInfo.InvariantCulture);
     var mkPointAnnotation = new MKPointAnnotation
     {
         Title = "You Are Here",
     };
     mkPointAnnotation.SetCoordinate(new CLLocationCoordinate2D(_iPhoneLocationManager.Location.Coordinate.Latitude, _iPhoneLocationManager.Location.Coordinate.Longitude));
     mapView.AddAnnotation(mkPointAnnotation);
 }
        public void UpdateMap( bool result )
        {
            GroupTableSource.SelectedIndex = -1;

            // remove existing annotations
            MapView.RemoveAnnotations( MapView.Annotations );

            // set the search results banner appropriately
            if ( GroupEntries.Count > 0 )
            {
                SearchResultsPrefix.Text = ConnectStrings.GroupFinder_Neighborhood;
                SearchResultsNeighborhood.Text = GroupEntries[ 0 ].NeighborhoodArea;

                // add an annotation for each position found in the group
                List<IMKAnnotation> annotations = new List<IMKAnnotation>();

                // add an annotation for the source
                MKPointAnnotation sourceAnnotation = new MKPointAnnotation();
                sourceAnnotation.SetCoordinate( new CLLocationCoordinate2D( SourceLocation.Latitude, SourceLocation.Longitude ) );
                sourceAnnotation.Title = "";
                sourceAnnotation.Subtitle = "";
                annotations.Add( sourceAnnotation );

                foreach ( GroupFinder.GroupEntry entry in GroupEntries )
                {
                    MKPointAnnotation annotation = new MKPointAnnotation();
                    annotation.SetCoordinate( new CLLocationCoordinate2D( entry.Latitude, entry.Longitude ) );
                    annotation.Title = entry.Title;
                    annotation.Subtitle = string.Format( "{0:##.0} {1}", entry.Distance, ConnectStrings.GroupFinder_MilesSuffix );
                    annotations.Add( annotation );
                }
                MapView.ShowAnnotations( annotations.ToArray( ), true );
            }
            else
            {
                if ( result == true )
                {
                    SearchResultsPrefix.Text = ConnectStrings.GroupFinder_NoGroupsFound;
                    SearchResultsNeighborhood.Text = string.Empty;

                    // since there were no groups, revert the map to whatever specified area
                    MKCoordinateRegion region = MKCoordinateRegion.FromDistance( new CLLocationCoordinate2D( 
                                                        ConnectConfig.GroupFinder_DefaultLatitude, 
                                                        ConnectConfig.GroupFinder_DefaultLongitude ), 
                                                    ConnectConfig.GroupFinder_DefaultScale_iOS, 
                                                    ConnectConfig.GroupFinder_DefaultScale_iOS );
                    MapView.SetRegion( region, true );
                }
                else
                {
                    SearchResultsPrefix.Text = ConnectStrings.GroupFinder_NetworkError;
                    SearchResultsNeighborhood.Text = string.Empty;
                }
            }

            UpdateResultsBanner( );
        }
		// This overridden method will be called after the AcquaintanceDetailViewController has been instantiated and loaded into memory,
		// but before the view hierarchy is rendered to the device screen.
		// The "async" keyword is added here to the override in order to allow other awaited async method calls inside the override to be called ascynchronously.
		public override async void ViewWillAppear(bool animated)
		{
			if (Acquaintance != null)
			{
				// set the title and label text properties
				Title = Acquaintance.DisplayName;
				CompanyNameLabel.Text = Acquaintance.Company;
				JobTitleLabel.Text = Acquaintance.JobTitle;
				StreetLabel.Text = Acquaintance.Street;
				CityLabel.Text = Acquaintance.City;
				StateAndPostalLabel.Text = Acquaintance.StatePostal;
				PhoneLabel.Text = Acquaintance.Phone;
				EmailLabel.Text = Acquaintance.Email;

				// Set image views for user actions.
				// The action for getting navigation directions is setup further down in this method, after the geocoding occurs.
				SetupSendMessageAction();
				SetupDialNumberAction();
				SetupSendEmailAction();

				// use FFImageLoading library to asynchronously:
				await ImageService
					.LoadFileFromApplicationBundle(String.Format(Acquaintance.PhotoUrl)) 	// get the image from the app bundle
					.LoadingPlaceholder("placeholderProfileImage.png") 						// specify a placeholder image
					.Transform(new CircleTransformation()) 									// transform the image to a circle
					.IntoAsync(ProfilePhotoImageView); 										// load the image into the UIImageView

				// use FFImageLoading library to asynchronously:
				//	await ImageService
				//		.LoadUrl(Acquaintance.PhotoUrl) 					// get the image from a URL
				//		.LoadingPlaceholder("placeholderProfileImage.png") 	// specify a placeholder image
				//		.Transform(new CircleTransformation()) 				// transform the image to a circle
				//		.IntoAsync(ProfilePhotoImageView); 					// load the image into the UIImageView
		

				// The FFImageLoading library has nicely transformed the image to a circle, but we need to use some iOS UIKit and CoreGraphics API calls to give it a colored border.
				double min = Math.Min(ProfilePhotoImageView.Frame.Height, ProfilePhotoImageView.Frame.Height);
				ProfilePhotoImageView.Layer.CornerRadius = (float)(min / 2.0);
				ProfilePhotoImageView.Layer.MasksToBounds = false;
				ProfilePhotoImageView.Layer.BorderColor = UIColor.FromRGB(84, 119, 153).CGColor;
				ProfilePhotoImageView.Layer.BorderWidth = 5;
				ProfilePhotoImageView.BackgroundColor = UIColor.Clear;
				ProfilePhotoImageView.ClipsToBounds = true;

				try
				{
					// asynchronously geocode the address
					var locations = await _Geocoder.GeocodeAddressAsync(Acquaintance.AddressString);

					// if we have at least one location
					if (locations != null && locations.Length > 0)
					{
						var coord = locations[0].Location.Coordinate;

						var span = new MKCoordinateSpan(MilesToLatitudeDegrees(20), MilesToLongitudeDegrees(20, coord.Latitude));

						// set the region that the map should display
						MapView.Region = new MKCoordinateRegion(coord, span);

						// create a new pin for the map
						var pin = new MKPointAnnotation() {
							Title = Acquaintance.DisplayName,
							Coordinate = new CLLocationCoordinate2D() {
								Latitude = coord.Latitude,
								Longitude = coord.Longitude
							}
						};

						// add the pin to the map
						MapView.AddAnnotation(pin);

						// add a top border to the MapView
						MapView.Layer.AddSublayer(new CALayer() {
							BackgroundColor = UIColor.LightGray.CGColor,
							Frame = new CGRect(0, 0, MapView.Frame.Width, 1)
						});

						// setup fhe action for getting navigation directions
						SetupGetDirectionsAction(coord.Latitude, coord.Longitude);
					}
				} catch (Exception ex)
				{
					DisplayErrorAlertView("Geocoding Error", "Please make sure the address is valid and that you have a network connection.");
				}
			}
		}
		void SetLocation ()
		{
			var placeLocation = viewModel.Place.Geometry.Location;
			var coordinates = new CLLocationCoordinate2D (placeLocation.Latitude, placeLocation.Longitude);

			ZoomInToMyLocation(coordinates);

			var placeAnnotation = new MKPointAnnotation {
				Coordinate = coordinates
			};

			MapView.AddAnnotation(placeAnnotation);
		}
		private void RepositionAnnotation(CLLocationCoordinate2D location)
		{
			string desc = "Your photo is here";
			
			if (ann == null)
			{
				ann = new MKPointAnnotation { Title = desc, Coordinate = location };				
			}
			else
			{
			 	mapView.RemoveAnnotation (ann);
				ann.Coordinate = location;
			}
						
			mapView.AddAnnotationObject (ann);
			LocationMapPhotoCapture = ScreenCapture ();
			mapView.SelectAnnotation (ann, false);
			
			ReverseGeocode(location);
		}		
		// Performs a natural language search for locations in the map's region that match the `searchBar`'s text.
		void PerformSearch ()
		{
			var request = new MKLocalSearchRequest ();
			request.NaturalLanguageQuery = SearchBar.Text;
			const double multiplier = RegionQueryDegreeMultiplier;
			var querySpan = new MKCoordinateSpan (MapView.Region.Span.LatitudeDelta * multiplier, MapView.Region.Span.LongitudeDelta * multiplier);
			request.Region = new MKCoordinateRegion (MapView.Region.Center, querySpan);

			var search = new MKLocalSearch (request);
			var matchingItems = new List<MKMapItem> ();

			search.Start ((response, error) => {
				MKMapItem[] mapItems = null;
				if (response != null)
					mapItems = response.MapItems ?? new MKMapItem[0];

				foreach (var item in mapItems) {
					matchingItems.Add (item);
					var annotation = new MKPointAnnotation ();
					annotation.Coordinate = item.Placemark.Coordinate;
					annotation.Title = item.Name;
					MapView.AddAnnotation (annotation);
				}
			});
		}