Ejemplo n.º 1
0
        void AddPolylines(IList polylines)
        {
            foreach (Polyline polyline in polylines)
            {
                var path = new MutablePath();
                foreach (var p in polyline.Positions)
                {
                    path.AddLatLon(p.Latitude, p.Longitude);
                }

                var nativePolyline = APolyline.FromPath(path);
                nativePolyline.StrokeWidth = polyline.StrokeWidth;
                nativePolyline.StrokeColor = polyline.StrokeColor.ToUIColor();
                nativePolyline.Tappable    = polyline.IsClickable;

                polyline.Id        = nativePolyline;
                nativePolyline.Map = (MapView)Control;
            }
        }
Ejemplo n.º 2
0
        public void DrawTripOnMap(string jsonResponse)
        {
            var directionData = JsonConvert.DeserializeObject <DirectionParser>(jsonResponse);
            var points        = directionData.routes[0].overview_polyline.points;

            // Draw Polyline on Map
            Google.Maps.Path     gmspath     = Google.Maps.Path.FromEncodedPath(points);
            Google.Maps.Polyline gmspolyline = Google.Maps.Polyline.FromPath(gmspath);
            gmspolyline.StrokeWidth = 4;
            gmspolyline.StrokeColor = UIColor.FromRGB(6, 144, 193);
            gmspolyline.Geodesic    = true;
            gmspolyline.Map         = map;

            double startlat = directionData.routes[0].legs[0].start_location.lat;
            double startlng = directionData.routes[0].legs[0].start_location.lng;
            double endlat   = directionData.routes[0].legs[0].end_location.lat;
            double endlng   = directionData.routes[0].legs[0].end_location.lng;

            pickupMarker          = new Marker();
            pickupMarker.Icon     = Marker.MarkerImage(UIColor.Green);
            pickupMarker.Title    = "Pickup Location";
            pickupMarker.Position = new CLLocationCoordinate2D(startlat, startlng);
            pickupMarker.Map      = map;
            pickupMarker.TracksInfoWindowChanges = true;

            driverlocationMarker       = new Marker();
            driverlocationMarker.Icon  = UIImage.FromBundle("posimarker");
            driverlocationMarker.Title = "Current Location";
            driverlocationMarker.TracksInfoWindowChanges = true;
            driverlocationMarker.Position = new CLLocationCoordinate2D(startlat, startlng);


            var destinationMarker = new Marker()
            {
                Title    = "Destination",
                Position = new CLLocationCoordinate2D(endlat, endlng),
                Map      = map,
                Icon     = Marker.MarkerImage(UIColor.Red)
            };

            Circle circleLocation = new Circle();

            circleLocation.Position    = new CLLocationCoordinate2D(startlat, startlng);
            circleLocation.Radius      = 8;
            circleLocation.StrokeColor = UIColor.FromRGB(6, 144, 193);
            circleLocation.FillColor   = UIColor.FromRGB(6, 144, 193);
            circleLocation.Map         = map;

            Circle circleDestination = new Circle();

            circleDestination.Position    = new CLLocationCoordinate2D(endlat, endlng);
            circleDestination.Radius      = 8;
            circleDestination.StrokeColor = UIColor.FromRGB(6, 144, 193);
            circleDestination.FillColor   = UIColor.FromRGB(6, 144, 193);
            circleDestination.Map         = map;

            CLLocationCoordinate2D southwest = new CLLocationCoordinate2D(directionData.routes[0].bounds.southwest.lat, directionData.routes[0].bounds.southwest.lng);
            CLLocationCoordinate2D northeast = new CLLocationCoordinate2D(directionData.routes[0].bounds.northeast.lat, directionData.routes[0].bounds.northeast.lng);

            CoordinateBounds bounds   = new CoordinateBounds(southwest, northeast);
            CameraUpdate     cupdates = CameraUpdate.FitBounds(bounds, 100);

            map.SelectedMarker = pickupMarker;
            map.Animate(cupdates);

            duration       = directionData.routes[0].legs[0].duration.value;
            distance       = directionData.routes[0].legs[0].distance.value;
            durationString = directionData.routes[0].legs[0].duration.text;
            distanceString = directionData.routes[0].legs[0].distance.text;
        }
Ejemplo n.º 3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            CameraPosition camera = CameraPosition.FromCamera(GetInitialCameraPosition(),
                                                              GetInitialCameraZoom());

            mapView = Google.Maps.MapView.FromCamera(CGRect.Empty, camera);
            mapView.MyLocationEnabled         = false;
            mapView.Settings.MyLocationButton = false;
            marker.IconView = new UIImageView(UIImage.FromBundle(ViewModel.Animal.ImageUrl));
            marker.Map      = mapView;
            var set = this.CreateBindingSet <MyAnimalActivityView, MyAnimalActivityViewModel>();

            set.Bind(NameLabel).To(vm => vm.Animal.Name);
            set.Bind(TypeLabel).To(vm => vm.Animal.Type);
            set.Bind(LocationLabel).To(vm => vm.Animal.Location);
            set.Apply();
            AnimLogoImageView.Transformations = ViewModel.Animal.AnimalImageTransformations;
            AnimLogoImageView.ImagePath       = ViewModel.Animal.ImageUrl;
            DateLabel.Text = ViewModel.Animal.BirthdateValue.ToString();

            View.AddSubview(mapView);
            mapView.Frame           = MapPlaceHolderView.Frame;
            ViewModel.Logs.Changed += delegate {
                if (ViewModel.Logs.Value != null)
                {
                    mapView.Animate(new CameraPosition(new CLLocationCoordinate2D(ViewModel.Logs.Value[0].Coordinate.Latitude,
                                                                                  ViewModel.Logs.Value[0].Coordinate.Longitude), defaultZoom));
                    Polylines = new Polyline[ViewModel.Logs.Value.Length - 1];
                    Dates     = new DateTime[ViewModel.Logs.Value.Length - 1];
                    Circles   = new Circle[ViewModel.Logs.Value.Length];
                    for (int i = 0; i < ViewModel.Logs.Value.Length - 1; i++)
                    {
                        var path     = new Google.Maps.MutablePath();
                        var polyline = new Google.Maps.Polyline();
                        path.AddCoordinate(new CLLocationCoordinate2D(latitude: ViewModel.Logs.Value[i].Coordinate.Latitude, longitude: ViewModel.Logs.Value[i].Coordinate.Longitude));
                        path.AddCoordinate(new CLLocationCoordinate2D(latitude: ViewModel.Logs.Value[i + 1].Coordinate.Latitude, longitude: ViewModel.Logs.Value[i + 1].Coordinate.Longitude));
                        polyline.Path        = path;
                        polyline.StrokeColor = CustomColor.JunctionXBlue;
                        polyline.StrokeWidth = 2.5f;
                        Polylines[i]         = polyline;
                        Dates[i]             = ViewModel.Logs.Value[i + 1].DateTimeValue;
                        var circle = new Circle();
                        circle.Position    = new CLLocationCoordinate2D(latitude: ViewModel.Logs.Value[i].Coordinate.Latitude, longitude: ViewModel.Logs.Value[i].Coordinate.Longitude);
                        circle.StrokeColor = CustomColor.JunctionXBlue;
                        circle.FillColor   = CustomColor.JunctionXBlue;
                        circle.Radius      = 7.5f;

                        Circles[i] = circle;
                        if (i + 1 == ViewModel.Logs.Value.Length - 1)
                        {
                            Circles[i + 1] = circle;
                        }
                    }
                    TimeLabel.Text         = Dates[0].ToString();
                    Slider.Value           = 0;
                    Slider.MinValue        = 0;
                    Slider.MaxValue        = ViewModel.Logs.Value.Length - 1;
                    Slider.TouchDragEnter += delegate {
                        animate = false;
                        StartButton.SetImage(UIImage.FromBundle("icPlayCircleFilled24Px"), UIControlState.Normal);
                    };
                    Slider.ValueChanged += delegate {
                        HandlePolylines();
                    };
                    HandlePolylines();

                    StartButton.TouchDown += delegate {
                        if ((int)Slider.Value != (int)Slider.MaxValue)
                        {
                            animate = !animate;
                            if (animate)
                            {
                                StartButton.SetImage(UIImage.FromBundle("icPauseCircleFilled24Px"), UIControlState.Normal);
                            }
                            else
                            {
                                StartButton.SetImage(UIImage.FromBundle("icPlayCircleFilled24Px"), UIControlState.Normal);
                            }
                            if (animate)
                            {
                                Animate();
                            }
                        }
                    };
                }
            };
        }
        public void DrawTripOnMap(string json)
        {
            var directionData = JsonConvert.DeserializeObject <DirectionParser>(json);

            var points = directionData.routes[0].overview_polyline.points;

            Google.Maps.Path     gmspath     = Google.Maps.Path.FromEncodedPath(points);
            Google.Maps.Polyline gmspolyline = Google.Maps.Polyline.FromPath(gmspath);
            gmspolyline.StrokeWidth = 4;
            gmspolyline.StrokeColor = UIColor.FromRGB(6, 144, 193);
            gmspolyline.Geodesic    = true;
            gmspolyline.Map         = googleMap;


            int pathCount = (int)gmspath.Count;

            for (int i = 0; i < pathCount; i++)
            {
                CLLocationCoordinate2D cPoint = gmspath.CoordinateAtIndex((nuint)i);
                Console.WriteLine("Position " + i.ToString() + " = " + cPoint.Latitude.ToString() + " , " + cPoint.Longitude.ToString());
            }

            double startlat = directionData.routes[0].legs[0].start_location.lat;
            double startlng = directionData.routes[0].legs[0].start_location.lng;
            double endlat   = directionData.routes[0].legs[0].end_location.lat;
            double endlng   = directionData.routes[0].legs[0].end_location.lng;

            Circle circleLocation = new Circle();

            circleLocation.Position    = new CLLocationCoordinate2D(startlat, startlng);
            circleLocation.Radius      = 8;
            circleLocation.StrokeColor = UIColor.FromRGB(6, 144, 193);
            circleLocation.FillColor   = UIColor.FromRGB(6, 144, 193);
            circleLocation.Map         = googleMap;

            Circle circleDestination = new Circle();

            circleDestination.Position    = new CLLocationCoordinate2D(endlat, endlng);
            circleDestination.Radius      = 8;
            circleDestination.StrokeColor = UIColor.FromRGB(6, 144, 193);
            circleDestination.FillColor   = UIColor.FromRGB(6, 144, 193);
            circleDestination.Map         = googleMap;

            //My take off position
            Marker currentLocationMarker = new Marker();

            currentLocationMarker.Icon     = Marker.MarkerImage(UIColor.Red);
            currentLocationMarker.Title    = "Current Location";
            currentLocationMarker.Position = new CLLocationCoordinate2D(startlat, startlng);
            currentLocationMarker.TracksInfoWindowChanges = true;
            currentLocationMarker.Map = googleMap;

            //Pickup Marker
            var pickupMarker = new Marker()
            {
                Title    = "Pick up Location",
                Position = new CLLocationCoordinate2D(endlat, endlng),
                Map      = googleMap,
                Icon     = Marker.MarkerImage(UIColor.Green)
            };


            // Constantly Changing Current Location marker
            positionMarker          = new Marker();
            positionMarker.Icon     = UIImage.FromBundle("posimarker");
            positionMarker.Title    = "Current Location";
            positionMarker.Position = new CLLocationCoordinate2D(startlat, startlng);
            positionMarker.TracksInfoWindowChanges = true;

            CLLocationCoordinate2D southwest = new CLLocationCoordinate2D(directionData.routes[0].bounds.southwest.lat, directionData.routes[0].bounds.southwest.lng);
            CLLocationCoordinate2D northeast = new CLLocationCoordinate2D(directionData.routes[0].bounds.northeast.lat, directionData.routes[0].bounds.northeast.lng);

            CoordinateBounds bounds   = new CoordinateBounds(southwest, northeast);
            CameraUpdate     cupdates = CameraUpdate.FitBounds(bounds, 100);

            googleMap.SelectedMarker = currentLocationMarker;
            googleMap.Animate(cupdates);

            duration       = directionData.routes[0].legs[0].duration.value;
            distance       = directionData.routes[0].legs[0].distance.value;
            durationString = directionData.routes[0].legs[0].duration.text;
            distanceString = directionData.routes[0].legs[0].distance.text;
        }