Example #1
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            RouteViews = new Dictionary <string, CSRouteView>();

            // load the points from local resource (file)
            var filePath     = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp", "");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List <CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var        latLonArr       = ps.Split(',');
                double     latitude        = Convert.ToDouble(latLonArr[0]);
                double     longitude       = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView       = new MKMapView();
            _mapView.Frame = new RectangleF(0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);


            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);

            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation(points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation(annotation);

            annotation = new CSMapAnnotation(points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation(annotation);

            //TODO:create the image annotation

            _mapView.SetRegion(routeAnnotation.Region, false);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            RouteViews = new Dictionary<string,CSRouteView>();

            // load the points from local resource (file)
            var filePath = NSBundle.MainBundle.PathForResource("route", "csv", "MapLineSharp","");
            var fileContents = System.IO.File.ReadAllText(filePath);
            var pointStrings = fileContents.Split('\n');

            var points = new List<CLLocation>();

            foreach (var ps in pointStrings)
            {
                // break the string down into latitude and longitude fields
                var latLonArr = ps.Split(',');
                double latitude = Convert.ToDouble(latLonArr[0]);
                double longitude = Convert.ToDouble(latLonArr[1]);
                CLLocation currentLocation = new CLLocation(latitude, longitude);
                points.Add(currentLocation);
            }
            //
            // Create our map view and add it as as subview.
            //
            _mapView = new MKMapView();
            _mapView.Frame = new RectangleF (0, 0, this.View.Frame.Width, this.View.Frame.Height);
            View.AddSubview(_mapView);
            _mapView.Delegate = new MapViewDelegate(this);

            // CREATE THE ANNOTATIONS AND ADD THEM TO THE MAP

            // first create the route annotation
            CSRouteAnnotation routeAnnotation = new CSRouteAnnotation(points);
            _mapView.AddAnnotation(routeAnnotation);

            CSMapAnnotation annotation = null;

            annotation = new CSMapAnnotation (points[0].Coordinate, CSMapAnnotationType.Start, "Start Point");
            _mapView.AddAnnotation (annotation);

            annotation = new CSMapAnnotation (points[points.Count - 1].Coordinate, CSMapAnnotationType.End, "End Point");
            _mapView.AddAnnotation (annotation);

            //TODO:create the image annotation

            _mapView.SetRegion (routeAnnotation.Region, false);
        }