예제 #1
0
        void AddMarkerInBounds(CoordinateBounds bounds)
        {
            double latitude = bounds.SouthWest.Latitude + GetRandomNumber() * (bounds.NorthEast.Latitude - bounds.SouthWest.Latitude);

            // If the visible region crosses the antimeridian (the right-most point is
            // "smaller" than the left-most point), adjust the longitude accordingly.
            bool   offset    = (bounds.NorthEast.Longitude < bounds.SouthWest.Longitude);
            double longitude = bounds.SouthWest.Longitude + GetRandomNumber() *
                               (bounds.NorthEast.Longitude - bounds.SouthWest.Longitude + (offset ? 360 : 0));

            if (longitude > 180)
            {
                longitude -= 360;
            }

            var color = UIColor.FromHSBA((float)GetRandomNumber(), 1, 1, 1.0f);

            var position = new CLLocationCoordinate2D(latitude, longitude);
            var marker   = Marker.FromPosition(position);

            marker.Title           = string.Format("Marker {0}", ++markerCount);
            marker.AppearAnimation = MarkerAnimation.Pop;
            marker.Icon            = Marker.MarkerImage(color);
            marker.Map             = mapView;
        }
예제 #2
0
        internal void MoveToRegion(MapSpan mapSpan, bool animated = true)
        {
            Position center    = mapSpan.Center;
            var      halfLat   = mapSpan.LatitudeDegrees / 2d;
            var      halfLong  = mapSpan.LongitudeDegrees / 2d;
            var      mapRegion = new CoordinateBounds(new VisibleRegion(
                                                          center.Latitude + halfLat,
                                                          center.Longitude + halfLong + (center.Longitude + halfLong > 180 ? -360 : 0),
                                                          center.Latitude + halfLat,
                                                          center.Longitude - halfLong + (center.Longitude - halfLong < -180 ? 360 : 0),
                                                          center.Latitude - halfLat,
                                                          center.Longitude + halfLong + (center.Longitude + halfLong > 180 ? -360 : 0),
                                                          center.Latitude - halfLat,
                                                          center.Longitude - halfLong + (center.Longitude - halfLong < -180 ? 360 : 0)));

            if (animated)
            {
                _nativeMap.Animate(GCameraUpdate.FitBounds(mapRegion));
            }
            else
            {
                _nativeMap.MoveCamera(GCameraUpdate.FitBounds(mapRegion));

                // TODO WORKARROUND for CameraPositionChanged does not raise when call MoveCamera with CameraUpdate.FitBounds(issue #189)
                _raiseCameraPositionChanged?.Invoke();
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            var southWest     = new CLLocationCoordinate2D(40.712216, -74.22655);
            var northEast     = new CLLocationCoordinate2D(40.773941, -74.12544);
            var overlayBounds = new CoordinateBounds(southWest, northEast);

            // Choose the midpoint of the coordinate to focus the camera on.
            var newark  = GeometryUtils.Interpolate(southWest, northEast, 0.5);
            var camera  = CameraPosition.FromCamera(newark, 12, 0, 45);
            var mapView = MapView.FromCamera(CGRect.Empty, camera);

            // Add the ground overlay, centered in Newark, NJ
            // Image from http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg
            var groundOverlay = new GroundOverlay()
            {
                Icon     = UIImage.FromBundle("newark_nj_1922.jpg"),
                Position = newark,
                Bounds   = overlayBounds,
                Map      = mapView
            };

            View = mapView;
        }
		void DidTapAdd (object sender, EventArgs e)
		{
			for (int i = 0; i < 10; ++i) {
				// Add a marker every 0.25 seconds for the next ten markers, randomly
				// within the bounds of the camera as it is at that point.
				var region = mapView.Projection.VisibleRegion;
				var bounds = new CoordinateBounds (region);
				AddMarkerInBounds (bounds);
				Thread.Sleep (250);
			}
		}
예제 #5
0
 void DidTapAdd(object sender, EventArgs e)
 {
     for (int i = 0; i < 10; ++i)
     {
         // Add a marker every 0.25 seconds for the next ten markers, randomly
         // within the bounds of the camera as it is at that point.
         var region = mapView.Projection.VisibleRegion;
         var bounds = new CoordinateBounds(region);
         AddMarkerInBounds(bounds);
         Thread.Sleep(250);
     }
 }
        void DidTapFitBounds(object sender, EventArgs e)
        {
            CoordinateBounds bounds = null;
            foreach (var marker in markers) {
                if (bounds == null)
                    bounds = new CoordinateBounds (marker.Position, marker.Position);

                bounds = bounds.Including (marker.Position);
            }
            var update = CameraUpdate.FitBounds (bounds, 50.0f);
            mapView.MoveCamera (update);
        }
예제 #7
0
        public void CalculatesCenterForCoordinateBounds()
        {
            CoordinateBounds ohioBounds = CoordinateBounds.Create(
                ne: Coordinates.Create(42.32324f, -80.51899f),
                sw: Coordinates.Create(38.40314f, -84.82034f));

            Assert.AreEqual(Coordinates.Create(40.36319f, -82.669665f), ohioBounds.Center);

            CoordinateBounds alaskaBounds = CoordinateBounds.Create(
                ne: Coordinates.Create(71.60482f, -129.9742f),
                sw: Coordinates.Create(51.02287f, 172.1155f));

            Assert.AreEqual(Coordinates.Create(61.3138428f, -158.929352f), alaskaBounds.Center);
        }
예제 #8
0
        /// <summary>
        /// Display's Place Picker UI
        /// </summary>
        /// <param name="bounds"></param>
        /// <returns></returns>
        public Task <Places> Display(CoordinateBounds bounds = null)
        {
            int id   = GetRequestId();
            var ntcs = new TaskCompletionSource <Places>(id);

            if (Interlocked.CompareExchange(ref this.completionSource, ntcs, null) != null)
            {
                throw new InvalidOperationException("Only one operation can be active at a time");
            }
            var currentactivity = CrossCurrentActivity.Current.Activity;
            var intent          = new Intent(currentactivity, typeof(PlacePickerActivity));

            intent.PutExtra(PlacePickerActivity.ExtraId, id);
            if (bounds != null)
            {
                intent.PutExtra(PlacePickerActivity.ExtraNELatitude, bounds.Northeast.Latitude);
                intent.PutExtra(PlacePickerActivity.ExtraNELongitude, bounds.Northeast.Longitude);
                intent.PutExtra(PlacePickerActivity.ExtraSWLatitude, bounds.Southwest.Latitude);
                intent.PutExtra(PlacePickerActivity.ExtraSWLongitude, bounds.Southwest.Longitude);
            }
            intent.AddFlags(ActivityFlags.NewTask);
            currentactivity.StartActivity(intent);
            EventHandler <PlacePickedEventArgs> handler = null;

            handler = (s, e) =>
            {
                var tcs = Interlocked.Exchange(ref this.completionSource, null);
                PlacePickerActivity.PlacePicked -= handler;

                if (e.RequestId != id)
                {
                    return;
                }
                if (e.IsCanceled)
                {
                    tcs.SetResult(null);
                }
                else if (e.Error != null)
                {
                    tcs.SetException(e.Error);
                }
                else
                {
                    tcs.SetResult(e.Places);
                }
            };
            PlacePickerActivity.PlacePicked += handler;
            return(completionSource.Task);
        }
예제 #9
0
        private void configureForMaps()
        {
            CreateMap <Model.Sites.Site, MapModel>()
            .ForMember(dest => dest.Zoom, opt => opt.UseValue(13))
            .ForMember(dest => dest.Center, opt => opt.MapFrom(src => src.CalculatedCoordinates))
            .ForMember(dest => dest.MarkerLoaderAction, opt => opt.MapFrom(src => MVC.Map.SiteMarker(src.Id)));

            CreateMap <Model.Trees.Tree, MapModel>()
            .ForMember(dest => dest.Zoom, opt => opt.UseValue(30))
            .ForMember(dest => dest.Center, opt => opt.MapFrom(src => src.CalculatedCoordinates))
            .ForMember(dest => dest.MarkerLoaderAction, opt => opt.MapFrom(src => MVC.Map.TreeMarker(src.Id)));

            CreateMap <IEnumerable <Model.Sites.Site>, MapModel>()
            .ForMember(dest => dest.Bounds, opt => opt.MapFrom(src => CoordinateBounds.Create(from site in src select site.Coordinates)))
            .ForMember(dest => dest.MarkerLoaderAction, opt => opt.MapFrom(src => MVC.Map.AllMarkers()));
        }
예제 #10
0
        private void CamerPostionIdle(Location location)
        {
            var bounds = new CoordinateBounds(_mapView.Projection.VisibleRegion);

            //CLLocationCoordinate2D northEast = bounds.NorthEast;
            //CLLocationCoordinate2D northWest = new CLLocationCoordinate2D(bounds.NorthEast.Latitude, bounds.SouthWest.Longitude);
            //CLLocationCoordinate2D southEast = new CLLocationCoordinate2D(bounds.SouthWest.Latitude, bounds.NorthEast.Longitude);
            //CLLocationCoordinate2D southWest = bounds.SouthWest;

            UIView.Animate(0.3, () =>
            {
                _myLocationButton.Hidden         = false;
                _setPickupLocationView.Transform = CGAffineTransform.MakeIdentity();
                _setPickupLocationView.Alpha     = 1;
            });
        }
        void SetNearestEventMarkers()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                ShowLoadingView(PortableLibrary.Constants.MSG_LOADING_ALL_MARKERS);

                MemberModel.rootMember = GetUserObject();

                mEventMarker = GetNearestEventMarkers(AppSettings.UserID);
                //mEventMarker = GetAllMarkers("58aafae816528b16d898a1f3");

                HideLoadingView();

                InvokeOnMainThread(() =>
                {
                    var boundPoints = new List <CLLocationCoordinate2D>();

                    if (mEventMarker != null && mEventMarker.markers.Count > 0)
                    {
                        for (int i = 0; i < mEventMarker.markers.Count; i++)
                        {
                            var point         = mEventMarker.markers[i];
                            var imgPin        = GetPinIconByType(point.type);
                            var pointLocation = new CLLocationCoordinate2D(point.lat, point.lng);
                            boundPoints.Add(pointLocation);

                            AddMapPin(pointLocation, imgPin, i);
                        }
                    }

                    if (boundPoints.Count > 0)
                    {
                        var mapBounds = new CoordinateBounds();

                        var myLocation   = LocationHelper.GetLocationResult();
                        var myLocation2D = new CLLocationCoordinate2D(myLocation.Latitude, myLocation.Longitude);
                        boundPoints.Add(myLocation2D);

                        foreach (var bound in boundPoints)
                        {
                            mapBounds = mapBounds.Including(bound);
                        }
                        mMapView.MoveCamera(CameraUpdate.FitBounds(mapBounds, 50.0f));
                    }
                });
            });
        }
        void DidTapFitBounds(object sender, EventArgs e)
        {
            CoordinateBounds bounds = null;

            foreach (var marker in markers)
            {
                if (bounds == null)
                {
                    bounds = new CoordinateBounds(marker.Position, marker.Position);
                }

                bounds = bounds.Including(marker.Position);
            }
            var update = CameraUpdate.FitBounds(bounds, 50.0f);

            mapView.MoveCamera(update);
        }
예제 #13
0
        public void ExtendsCoordinateBounds()
        {
            CoordinateBounds cb1 = CoordinateBounds.Null();

            Assert.AreEqual(cb1.NE, Coordinates.Null());
            Assert.AreEqual(cb1.SW, Coordinates.Null());
            Assert.AreEqual(cb1.Center, Coordinates.Null());

            CoordinateBounds cb2 = CoordinateBounds.Null()
                                   .Extend(Coordinates.Create(50, 50))
                                   .Extend(Coordinates.Create(25, 75))
                                   .Extend(Coordinates.Create(75, 25));

            Assert.AreEqual(cb2.NE, Coordinates.Create(75, 75));
            Assert.AreEqual(cb2.SW, Coordinates.Create(25, 25));
            Assert.AreEqual(cb2.Center, Coordinates.Create(50, 50));
        }
예제 #14
0
        void MoveToRegion(MapSpan mapSpan, bool animated = true)
        {
            Position center    = mapSpan.Center;
            var      halfLat   = mapSpan.LatitudeDegrees / 2d;
            var      halfLong  = mapSpan.LongitudeDegrees / 2d;
            var      mapRegion = new CoordinateBounds(new CLLocationCoordinate2D(center.Latitude - halfLat, center.Longitude - halfLong),
                                                      new CLLocationCoordinate2D(center.Latitude + halfLat, center.Longitude + halfLong));

            if (animated)
            {
                ((MapView)Control).Animate(CameraUpdate.FitBounds(mapRegion));
            }
            else
            {
                ((MapView)Control).MoveCamera(CameraUpdate.FitBounds(mapRegion));
            }
        }
예제 #15
0
 /// <summary>
 /// OnActivity Result
 /// </summary>
 /// <param name="requestCode"></param>
 /// <param name="resultCode"></param>
 /// <param name="data"></param>
 protected override void OnActivityResult(int requestCode, Result resultCode, Intent data)
 {
     base.OnActivityResult(requestCode, resultCode, data);
     if (requestCode != REQUEST_PLACE_PICKER)
     {
         return;
     }
     if (resultCode == Result.Ok)
     {
         var         place       = PlacePicker.GetPlace(this, data);
         var         name        = place.NameFormatted.ToString();
         var         placeId     = place.Id;
         var         coordinate  = place.LatLng;
         Coordinates coordinates = null;
         if (place.LatLng?.Latitude != null && place.LatLng?.Longitude != null)
         {
             coordinates = new Coordinates(coordinate.Latitude, coordinate.Longitude);
         }
         var phone               = place.PhoneNumberFormatted?.ToString();
         var address             = place.AddressFormatted?.ToString();
         var attribution         = place.AttributionsFormatted?.ToString();
         var weburi              = place.WebsiteUri?.ToString();
         var priceLevel          = place.PriceLevel;
         var rating              = place.Rating;
         var swlatitude          = place.Viewport?.Southwest.Latitude;
         var swlongitude         = place.Viewport?.Southwest.Longitude;
         var nelatitude          = place.Viewport?.Northeast.Latitude;
         var nelongitude         = place.Viewport?.Northeast.Longitude;
         CoordinateBounds bounds = null;
         if (swlatitude != null && swlongitude != null && nelatitude != null && nelongitude != null)
         {
             bounds = new CoordinateBounds(new Coordinates(swlatitude.Value, swlongitude.Value), new Coordinates(nelatitude.Value, nelongitude.Value));
         }
         Places places = new Places(name, placeId, coordinates, phone, address, attribution, weburi, priceLevel, rating, bounds);
         OnPlaceSelected(new PlacePickedEventArgs(this.id, false, places));
         Finish();
         return;
     }
     else
     {
         OnPlaceSelected(new PlacePickedEventArgs(this.id, true));
         Finish();
         return;
     }
 }
예제 #16
0
        async private void WithBounds_Clicked(object sender, EventArgs e)
        {
            try
            {
                var southWest        = new Coordinates(85, -180);
                var northEast        = new Coordinates(-85, 180);
                var CoordinateBounds = new CoordinateBounds(southWest, northEast);
                var result           = await CrossPlacePicker.Current.Display(CoordinateBounds);

                if (result != null)
                {
                    await DisplayAlert(result.Name, "Latitude: " + result.Coordinates.Latitude + "\nLongitude: " + result.Coordinates.Longitude, "OK");
                }
            }
            catch (Exception ex)
            {
                await DisplayAlert("Error", ex.ToString(), "Oops");
            }
        }
예제 #17
0
        private void MapView_CameraPositionIdle(object sender, GMSCameraEventArgs e)
        {
            var visibleRegion = mapView.Projection.VisibleRegion;
            var bounds        = new CoordinateBounds(visibleRegion);

            lastCameraPosition = mapView.Camera.Target;
            lastCameraZoom     = mapView.Camera.Zoom;
            //ViewModel.CurrentBounds.Value = new GeoLocationBounds
            //{
            //    NorthEast = new MvxCoordinates
            //    {
            //        Longitude = bounds.NorthEast.Longitude,
            //        Latitude = bounds.NorthEast.Latitude
            //    },
            //    SouthWest = new MvxCoordinates
            //    {
            //        Longitude = bounds.SouthWest.Longitude,
            //        Latitude = bounds.SouthWest.Latitude
            //    }
            //};
        }
예제 #18
0
		void AddMarkerInBounds (CoordinateBounds bounds)
		{
			double latitude = bounds.SouthWest.Latitude + GetRandomNumber() * (bounds.NorthEast.Latitude - bounds.SouthWest.Latitude);
						
			// If the visible region crosses the antimeridian (the right-most point is
			// "smaller" than the left-most point), adjust the longitude accordingly.
			bool offset = (bounds.NorthEast.Longitude < bounds.SouthWest.Longitude);
			double longitude = bounds.SouthWest.Longitude + GetRandomNumber() * 
				(bounds.NorthEast.Longitude - bounds.SouthWest.Longitude + (offset ? 360 : 0));

			if (longitude > 180)
				longitude -= 360;
			
			var color =	UIColor.FromHSBA ((float)GetRandomNumber(), 1, 1, 1.0f);
						
			var position = new CLLocationCoordinate2D (latitude, longitude);
			var marker = Marker.FromPosition (position);
			marker.Title = string.Format ("Marker {0}", ++markerCount);
			marker.Animated = true;
			marker.Icon = Marker.MarkerImage (color);
			marker.Map = mapView;
		}
예제 #19
0
        public virtual Coordinates CalculateCoordinates(bool ignoreContainingTrip = false)
        {
            if (Coordinates.IsValidAndSpecified())
            {
                return(Coordinates);
            }

            var bounds = CoordinateBounds.Create(Trees
                                                 .Where(tm => tm.CanCalculateCoordinates(true)).Select(tm => tm.CalculateCoordinates(true)));

            if (bounds.IsSpecified)
            {
                return(bounds.Center);
            }

            if (!ignoreContainingTrip && Trip.CanCalculateCoordinates())
            {
                return(Trip.CalculateCoordinates());
            }

            return(Coordinates.Null());
        }
예제 #20
0
            public void OnSearchResult(Java.Lang.Object resultObject)
            {
                DetailSearchResponse detailSearchResponse = (DetailSearchResponse)resultObject;
                StringBuilder        resultText           = new StringBuilder();
                Site site = detailSearchResponse.Site;

                if (site == null)
                {
                    ResultTextView.Text = "Result is Empty!";
                    return;
                }

                System.Text.StringBuilder ResultText = new System.Text.StringBuilder();
                ResultText.AppendLine("Success");
                AddressDetail    addressDetail = site.Address;
                Coordinate       location      = site.Location;
                Poi              poi           = site.Poi;
                CoordinateBounds viewport      = site.Viewport;

                string item = "siteId: '{0}', name: {1}, formatAddress: {2}, country: {3}, countryCode: {4}, location: {5}, poiTypes: {6}, viewport: {7} ";

                ResultText.Append(string.Format(item,
                                                site.SiteId, site.Name, site.FormatAddress,
                                                (addressDetail == null ? "" : addressDetail.Country),
                                                (addressDetail == null ? "" : addressDetail.CountryCode),
                                                (location == null ? "" : (location.Lat + "," + location.Lng)),
                                                (poi == null ? "" : string.Join(",", poi.PoiTypes.ToArray())),
                                                (viewport == null ? "" : "northeast{lat=" + viewport.Northeast.Lat + ", lng=" + viewport.Northeast.Lng + "},"
                                                 + "southwest{lat=" + viewport.Southwest.Lat + ", lng=" + viewport.Southwest.Lng + "}")));
                if ((poi != null))
                {
                    Gson   gson       = new Gson();
                    string jsonString = gson.ToJson(poi.GetChildrenNodes());
                    ResultText.Append(string.Format("childrenNode: {0} \n\n", jsonString));
                }

                ResultTextView.Text = ResultText.ToString();
                Log.Debug(KeywordSearchActivity.TAG, "OnDetailSearchResult: " + ResultText.ToString());
            }
            public bool DidTapCluster(GMUClusterManager clusterManager, IGMUCluster cluster)
            {
                // zoom to expand the cluster
                var bounds = new CoordinateBounds(cluster.Position, cluster.Position);

                foreach (var item in cluster.Items)
                {
                    bounds = bounds.Including(item.Position);
                }

                try
                {
                    var cameraUpdate = CameraUpdate.FitBounds(bounds, 100);
                    mapView.MoveCamera(cameraUpdate);
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine(ex.StackTrace);
                }

                return(true);
            }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var southWest = new CLLocationCoordinate2D (40.712216, -74.22655);
            var northEast = new CLLocationCoordinate2D (40.773941, -74.12544);
            var overlayBounds = new CoordinateBounds (southWest, northEast);

            // Choose the midpoint of the coordinate to focus the camera on.
            var newark = GeometryUtils.Interpolate (southWest, northEast, 0.5);
            var camera = CameraPosition.FromCamera (newark, 12, 0, 45);
            var mapView = MapView.FromCamera (RectangleF.Empty, camera);

            // Add the ground overlay, centered in Newark, NJ
            // Image from http://www.lib.utexas.edu/maps/historical/newark_nj_1922.jpg
            var groundOverlay = new GroundOverlay () {
                Icon = UIImage.FromBundle ("newark_nj_1922.jpg"),
                Position = newark,
                Bounds = overlayBounds,
                Map = mapView
            };

            View = mapView;
        }
        public async Task GetNearestDomainAddresses()
        {
            var addressKind = AddressKind.City;
            var coordinate  = new Coordinate {
                Latitude = 1.3, Longitude = 2.3
            };
            var maxResultCount   = 3;
            var distance         = 500;
            var coordinateBounds = new CoordinateBounds
            {
                Latitude     = coordinate.Latitude,
                Longitude    = coordinate.Longitude,
                MinLatitude  = 1,
                MinLongitude = 2,
                MaxLatitude  = 3,
                MaxLongitude = 4
            };

            var domainAddresses = new List <Address>
            {
                new Address {
                    Id = 1, Latitude = 1.1, Longitude = 2.1
                },
                new Address {
                    Id = 2, Latitude = 1.2, Longitude = 2.2
                },
                new Address {
                    Id = 3, Latitude = 1.3, Longitude = 2.3
                },
                new Address {
                    Id = 4, Latitude = 1.4, Longitude = 2.4
                },
                new Address {
                    Id = 5, Latitude = 1.5, Longitude = 2.5
                }
            };

            var coordinates        = domainAddresses.Select(address => address.ToCoordinate()).ToList();
            var orderedCoordinates = coordinates.GetRange(1, 3);

            Suite.DirectionServiceMock
            .Setup(m => m.GetCoordinateBounds(coordinate, distance))
            .ReturnsAsync(coordinateBounds);
            Suite.DomainAddressServiceMock
            .Setup(m => m.GetByCoordinateBounds(
                       addressKind,
                       coordinateBounds.MinLatitude,
                       coordinateBounds.MinLongitude,
                       coordinateBounds.MaxLatitude,
                       coordinateBounds.MaxLongitude))
            .ReturnsAsync(domainAddresses);
            Suite.DirectionServiceMock
            .Setup(m => m.GetNearestCoordinates(coordinate, It.IsAny <IEnumerable <Coordinate> >(), maxResultCount))
            .ReturnsAsync(orderedCoordinates);

            var result = await Suite.AddressService.GetNearestAddresses(addressKind, coordinate, distance, maxResultCount);

            Assert.Equal(maxResultCount, result.Count);

            Assert.Equal(1.2, result.ElementAt(0).Latitude);
            Assert.Equal(2.2, result.ElementAt(0).Longitude);

            Assert.Equal(1.3, result.ElementAt(1).Latitude);
            Assert.Equal(2.3, result.ElementAt(1).Longitude);

            Assert.Equal(1.4, result.ElementAt(2).Latitude);
            Assert.Equal(2.4, result.ElementAt(2).Longitude);
        }
예제 #24
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;
        }
예제 #26
0
 public virtual Coordinates CalculateCoordinates()
 {
     return(CoordinateBounds.Create(Sites
                                    .Where(s => s.CanCalculateCoordinates(true)).Select(s => s.CalculateCoordinates(true)))
            .Center);
 }
예제 #27
0
        public void FitUserAndMarker(CLLocationCoordinate2D desPosition)
        {
            CoordinateBounds mapBounds = new CoordinateBounds(UserPositon, desPosition);

            this.Animate(CameraUpdate.FitBounds(mapBounds, new UIEdgeInsets(50, 35, 50, 35)));
        }
예제 #28
0
        void GetMarkersAndPoints()
        {
            System.Threading.ThreadPool.QueueUserWorkItem(delegate
            {
                ShowLoadingView(PortableLibrary.Constants.MSG_LOADING_ALL_MARKERS);

                mEventMarker    = GetAllMarkers(eventID);
                var trackPoints = GetTrackPoints(eventID);

                HideLoadingView();

                InvokeOnMainThread(() =>
                {
                    var boundPoints = new List <CLLocationCoordinate2D>();

                    if (mEventMarker != null && mEventMarker.markers.Count > 0)
                    {
                        for (int i = 0; i < mEventMarker.markers.Count; i++)
                        {
                            var point         = mEventMarker.markers[i];
                            var imgPin        = GetPinIconByType(point.type);
                            var pointLocation = new CLLocationCoordinate2D(point.lat, point.lng);
                            boundPoints.Add(pointLocation);

                            AddMapPin(pointLocation, imgPin, i);
                        }
                    }

                    if (trackPoints != null && trackPoints.Count > 0)
                    {
                        if (trackPoints[0].Count > 0)
                        {
                            var startPoint    = trackPoints[0][0];
                            var endPoint      = trackPoints[trackPoints.Count - 1][trackPoints[trackPoints.Count - 1].Count - 1];
                            var startLocation = new CLLocationCoordinate2D(startPoint.Latitude, startPoint.Longitude);
                            var endLocation   = new CLLocationCoordinate2D(endPoint.Latitude, endPoint.Longitude);
                            AddMapPin(startLocation, GetPinIconByType("pSTART"), -1);
                            AddMapPin(endLocation, GetPinIconByType("pFINISH"), -1);
                        }

                        for (int i = 0; i < trackPoints.Count; i++)
                        {
                            var tPoints = trackPoints[i];

                            var path     = new MutablePath();
                            var polyline = new Polyline();

                            for (int j = 0; j < tPoints.Count; j++)
                            {
                                var tPoint    = tPoints[j];
                                var tLocation = new CLLocationCoordinate2D(tPoint.Latitude, tPoint.Longitude);

                                if (j < tPoints.Count - 1)
                                {
                                    var distance = DistanceAtoB(tPoint, tPoints[j + 1]);

                                    if (PortableLibrary.Constants.AVAILABLE_DISTANCE_MAP > distance)
                                    {
                                        var nPoint = tPoints[j + 1];
                                        path.AddCoordinate(tLocation);
                                    }
                                    else
                                    {
                                        polyline.Path        = path;
                                        polyline.StrokeColor = GetRandomColor(i);
                                        polyline.StrokeWidth = 5;
                                        polyline.Geodesic    = true;
                                        polyline.Map         = mMapView;

                                        path     = new MutablePath();
                                        polyline = new Polyline();
                                    }
                                }

                                polyline.Path        = path;
                                polyline.StrokeColor = GetRandomColor(i);
                                polyline.StrokeWidth = 5;
                                polyline.Geodesic    = true;
                                polyline.Map         = mMapView;

                                boundPoints.Add(tLocation);
                            }
                        }
                    }

                    if (boundPoints.Count == 0)
                    {
                        var camera = CameraPosition.FromCamera(PortableLibrary.Constants.LOCATION_ISURAEL[0], PortableLibrary.Constants.LOCATION_ISURAEL[1], zoom: PortableLibrary.Constants.MAP_ZOOM_LEVEL);
                        mMapView   = MapView.FromCamera(RectangleF.Empty, camera);
                    }
                    else
                    {
                        var mapBounds = new CoordinateBounds();
                        foreach (var bound in boundPoints)
                        {
                            mapBounds = mapBounds.Including(bound);
                        }
                        mMapView.MoveCamera(CameraUpdate.FitBounds(mapBounds, 50.0f));
                    }
                });
            });
        }
예제 #29
0
        void MoveToRegion(MapSpan mapSpan, bool animated = true)
        {
            Position center = mapSpan.Center;
            var halfLat = mapSpan.LatitudeDegrees / 2d;
            var halfLong = mapSpan.LongitudeDegrees / 2d;
            var mapRegion = new CoordinateBounds(new CLLocationCoordinate2D(center.Latitude - halfLat, center.Longitude - halfLong),
                                                new CLLocationCoordinate2D(center.Latitude + halfLat, center.Longitude + halfLong));

            if (animated)
                ((MapView)Control).Animate(CameraUpdate.FitBounds(mapRegion));
            else
                ((MapView)Control).MoveCamera(CameraUpdate.FitBounds(mapRegion));
        }
예제 #30
0
        public void ExecPlaceSuggestionSearch()
        {
            QuerySuggestionRequest QuerySuggestionRequest = new QuerySuggestionRequest();

            if (QueryInput.Text.Length == 0)
            {
                ResultTextView.Text = "Error : Query is empty!";
                return;
            }
            QuerySuggestionRequest.Query = QueryInput.Text;


            if (!string.IsNullOrEmpty(LanguageInput.Text))
            {
                QuerySuggestionRequest.Language = LanguageInput.Text;
            }

            if (!string.IsNullOrEmpty(CountryCodeInput.Text))
            {
                QuerySuggestionRequest.CountryCode = CountryCodeInput.Text;
            }

            double lat;
            double lon;

            if (!string.IsNullOrEmpty(LatitudeInput.Text) || !string.IsNullOrEmpty(LongitudeInput.Text))
            {
                if (!(double.TryParse(LatitudeInput.Text, out lat)) || !(double.TryParse(LongitudeInput.Text, out lon)))
                {
                    ResultTextView.Text = "Error : Location is invalid!";
                    return;
                }
                QuerySuggestionRequest.Location = new Coordinate(lat, lon);
            }

            int radiusInt;

            if (!(Int32.TryParse(RadiusInput.Text, out radiusInt)) || radiusInt <= 0)
            {
                ResultTextView.Text = "Error : Radius Must be greater than 0 !";
                return;
            }
            QuerySuggestionRequest.Radius = (Integer)radiusInt;


            if (!string.IsNullOrEmpty(NortheastLatInput.Text) && !string.IsNullOrEmpty(NortheastLngInput.Text) && !string.IsNullOrEmpty(SouthwestLatInput.Text) && !string.IsNullOrEmpty(SouthwestLngInput.Text))
            {
                Coordinate       northeast = new Coordinate(double.Parse(NortheastLatInput.Text), double.Parse(NortheastLngInput.Text));
                Coordinate       southwest = new Coordinate(double.Parse(SouthwestLatInput.Text), double.Parse(SouthwestLngInput.Text));
                CoordinateBounds bounds    = new CoordinateBounds(northeast, southwest);
                QuerySuggestionRequest.Bounds = bounds;
            }

            QuerySuggestionRequest.Children     = Childern.Checked;
            QuerySuggestionRequest.StrictBounds = (Java.Lang.Boolean)BoundStrict.Checked;

            QuerySuggestionResultListener querySuggestionResultListener = new QuerySuggestionResultListener();

            // Call the search API.
            SearchService.QuerySuggestion(QuerySuggestionRequest, querySuggestionResultListener);
        }
예제 #31
0
        private async void GetMyValidBookedReservations()
        {
            ShowLoadingView("Loading data...");

            _pickups = new List <Dictionary <string, string> > ();

            try
            {
                var lResult = LocationHelper.GetLocationResult();

                if (_selectedMarker != null)
                {
                    _selectedMarker.Map = null;
                    mapView.Clear();
                }


                if (_currentMarkers != null)
                {
                    foreach (var marker in _currentMarkers)
                    {
                        marker.Map = null;
                    }
                    _currentMarkers.Clear();
                    mapView.MarkerInfoWindow = null;
                }

                NSDateFormatter dateFormat = new NSDateFormatter();
                dateFormat.DateFormat = "MM/dd/yyyy";
                NSDate now    = NSDate.FromTimeIntervalSinceReferenceDate((DateTime.Now - (new DateTime(2001, 1, 1, 0, 0, 0))).TotalSeconds);
                var    strNow = dateFormat.ToString(now);

                var customerID = AppSettings.UserID;


                // please take a look it, Pavel
                var dic = new Dictionary <String, String>
                {
                    { Constant.GETREADYFORPICKUPLIST_CUSTOMERID, "553890" },
                    { Constant.GETREADYFORPICKUPLIST_CURRENTDATE, "2/13/2015" }
                };
                //var dic = new Dictionary<String, String>
                //{
                //	{Constant.GETREADYFORPICKUPLIST_CUSTOMERID, customerID},
                //	{Constant.GETREADYFORPICKUPLIST_CURRENTDATE, strNow}
                //};
                var result = await AppData.ApiCall(Constant.GETREADYFORPICKUPLIST, dic);

                var tt = (GetReadyForPickupListResponse)AppData.ParseResponse(Constant.GETREADYFORPICKUPLIST, result);

                var availableReservations = tt.PickupList;

                for (int i = 0; i < availableReservations.Count; i++)
                {
                    var reservation = availableReservations[i];

                    Task runSync = Task.Factory.StartNew(async() => {
                        var pickupData = await GetPickupDataForReservation(reservation);
                        _pickups.Add(pickupData);
                    }).Unwrap();
                    runSync.Wait();
                }

                var bounds = new CoordinateBounds();

                var listReservations = new List <KeyValuePair <object, string> >();
                listReservations.Add(new KeyValuePair <object, string>("0", "Ready for all rides"));
                foreach (Dictionary <String, String> pickup in _pickups)
                {
                    var marker = new Marker
                    {
                        Position = new CLLocationCoordinate2D(double.Parse(pickup["Latitude"]), double.Parse(pickup["Longitude"])),
                        Map      = mapView,
                        Icon     = rotateImage(UIImage.FromBundle(getMapVehicleIconByServiceID(pickup["ServiceID"])), float.Parse(pickup["Angle"])),
                        ZIndex   = int.Parse(pickup["ResID"])
                    };
                    _currentMarkers.Add(marker);
                    bounds = bounds.Including(marker.Position);

                    listReservations.Add(new KeyValuePair <object, string>(pickup["ResID"], pickup["DisplayTxt"]));                   //string.Format("Shared Van (7 Passengers) \n 3:45 Pick-Up to Los Angeles", pickup["ResID"], pickup["ResType"])));
                }

                if (_pickups.Count > 0)
                {
                    btnReadyPickup.BackgroundColor = UIColor.Green;
                    btnReadyPickup.SetTitle(string.Format("READY FOR PICKUP ({0})", _pickups.Count.ToString()), UIControlState.Normal);
                    SetupReadyPickup(txtBtnReadyPickup, listReservations, CallForReadyPickup);
                }
                else
                {
                    btnReadyPickup.BackgroundColor = UIColor.Gray;
                    btnReadyPickup.SetTitle("READY FOR PICKUP", UIControlState.Normal);
                }

                bounds = bounds.Including(new CLLocationCoordinate2D(lResult.Latitude, lResult.Longitude));

                _selectedMarker = new Marker {
                    Position = new CLLocationCoordinate2D(lResult.Latitude, lResult.Longitude),
                    Map      = mapView,
                    Icon     = UIImage.FromBundle("icon_mylocation.png")
                };

                mapView.SelectedMarker = _selectedMarker;

                if (_pickups.Count > 0)
                {
                    mapView.Animate(CameraUpdate.FitBounds(bounds, 100f));
                }

                mapView.TappedMarker = (map, maker) => {
                    mapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow);
                    return(false);
                };
            }
            catch (Exception ex)
            {
                CrashReporter.Report(ex);
                HideLoadingView();
                return;
            }
            HideLoadingView();
        }