예제 #1
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;
        }
        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;
        }