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); }
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)); } }
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 void cameraAutoZoomAndReposition(Event[] eventMarkers) { double minimumLongitudeInGoogle = 180.0f; double maximumLongitudeInGoogle = -180.0f; double minimumLatitudeInGoogle = 90.0f; double maximumLatitudeInGoogle = -90.0f; foreach (Event currentMarker in eventMarkers) { maximumLongitudeInGoogle = Math.Max(maximumLongitudeInGoogle, currentMarker.Location.Longitude); minimumLongitudeInGoogle = Math.Min(minimumLongitudeInGoogle, currentMarker.Location.Longitude); maximumLatitudeInGoogle = Math.Max(maximumLatitudeInGoogle, currentMarker.Location.Latitude); minimumLatitudeInGoogle = Math.Min(minimumLatitudeInGoogle, currentMarker.Location.Latitude); } CLLocationCoordinate2D northWestBound = new CLLocationCoordinate2D(maximumLatitudeInGoogle, minimumLongitudeInGoogle); CLLocationCoordinate2D southEastBound = new CLLocationCoordinate2D(minimumLatitudeInGoogle, maximumLongitudeInGoogle); mapView.MoveCamera(CameraUpdate.FitBounds(new CoordinateBounds(northWestBound, southEastBound))); float desiredZoomlevel = (float)(getZoomLevel(minimumLatitudeInGoogle, maximumLatitudeInGoogle, minimumLongitudeInGoogle, maximumLongitudeInGoogle, mapViewOutlet.Frame.Size.Width, mapViewOutlet.Frame.Size.Height)); mapView.MoveCamera(CameraUpdate.ZoomToZoom(desiredZoomlevel)); }
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; }
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)); } }); }); }
public void FitUserAndMarker(CLLocationCoordinate2D desPosition) { CoordinateBounds mapBounds = new CoordinateBounds(UserPositon, desPosition); this.Animate(CameraUpdate.FitBounds(mapBounds, new UIEdgeInsets(50, 35, 50, 35))); }
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(); }
void OnTouchUpInside(object sender, EventArgs e) { ctrl.ButtonPressed(null); if (sender is UIButton && ((UIButton)sender).Tag == 1) { // Ask, which to show var thingOffset = 1; UIActionSheet actionSheet = new UIActionSheet(Catalog.GetString("Focus on")); if (thing != null) { actionSheet.AddButton(thing.Name); thingOffset = 0; } actionSheet.AddButton(Catalog.GetString("Playing area")); actionSheet.AddButton(Catalog.GetString("Location")); actionSheet.AddButton(Catalog.GetString("Cancel")); actionSheet.CancelButtonIndex = 3 - thingOffset; // Black button actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) { CameraUpdate cu = null; if (b.ButtonIndex == 0 - thingOffset) { // Location of thing is selected and thing is a zone if (thing is Zone) { var bounds = ((Zone)thing).Bounds; // cu = CameraUpdate.FitBounds(new CoordinateBounds(new CLLocationCoordinate2D(lat1, lon1),new CLLocationCoordinate2D(lat2, lon2)),30f); cu = CameraUpdate.SetTarget(new CLLocationCoordinate2D(bounds.Left + (bounds.Right - bounds.Left) / 2.0, bounds.Bottom + (bounds.Top - bounds.Bottom) / 2.0)); } else { // Location of thing is selected and thing is no zone if (thing.ObjectLocation != null) { cu = CameraUpdate.SetTarget(new CLLocationCoordinate2D(thing.ObjectLocation.Latitude, thing.ObjectLocation.Longitude)); } } } if (b.ButtonIndex == 1 - thingOffset) { var bounds = engine.Bounds; if (bounds != null) { cu = CameraUpdate.FitBounds(new CoordinateBounds(new CLLocationCoordinate2D(bounds.Left, bounds.Top), new CLLocationCoordinate2D(bounds.Right, bounds.Bottom)), 30f); } } if (b.ButtonIndex == 2 - thingOffset) { // Location of player is selected cu = CameraUpdate.SetTarget(new CLLocationCoordinate2D(engine.Latitude, engine.Longitude)); } if (cu != null) { mapView.MoveCamera(cu); } }; actionSheet.ShowInView(View); } if (sender is UIButton && ((UIButton)sender).Tag == 2) { // Check, if north should be on top headingOrientation = !headingOrientation; NSUserDefaults.StandardUserDefaults.SetBool(headingOrientation, "HeadingOrientation"); if (headingOrientation) { ((UIButton)sender).SetImage(Images.ButtonOrientation, UIControlState.Normal); ctrl.LocatitionManager.UpdatedHeading += OnUpdateHeading; } else { ((UIButton)sender).SetImage(Images.ButtonOrientationNorth, UIControlState.Normal); ctrl.LocatitionManager.UpdatedHeading -= OnUpdateHeading; mapView.AnimateToBearing(0.0); } } if (sender is UIButton && ((UIButton)sender).Tag == 3) { // Change map type // Ask, which to show UIActionSheet actionSheet = new UIActionSheet(Catalog.GetString("Type of map")); actionSheet.AddButton((mapView.MapType == MapViewType.Normal ? Strings.Checked + " " : "") + Catalog.GetString("Google Maps")); actionSheet.AddButton((mapView.MapType == MapViewType.Satellite ? Strings.Checked + " " : "") + Catalog.GetString("Google Satellite")); actionSheet.AddButton((mapView.MapType == MapViewType.Terrain ? Strings.Checked + " " : "") + Catalog.GetString("Google Terrain")); actionSheet.AddButton((mapView.MapType == MapViewType.Hybrid ? Strings.Checked + " " : "") + Catalog.GetString("Google Hybrid")); actionSheet.AddButton((mapView.MapType == MapViewType.None && osmLayer.Map != null ? Strings.Checked + " " : "") + Catalog.GetString("OpenStreetMap")); actionSheet.AddButton((mapView.MapType == MapViewType.None && ocmLayer.Map != null ? Strings.Checked + " " : "") + Catalog.GetString("OpenCycleMap")); actionSheet.AddButton((mapView.MapType == MapViewType.None && osmLayer.Map == null && ocmLayer.Map == null ? Strings.Checked + " " : "") + Catalog.GetString("None")); actionSheet.AddButton(Catalog.GetString("Cancel")); actionSheet.CancelButtonIndex = 7; // Black button actionSheet.Clicked += delegate(object a, UIButtonEventArgs b) { switch (b.ButtonIndex) { case 0: SetMapSource(MapSource.GoogleMaps); break; case 1: SetMapSource(MapSource.GoogleSatellite); break; case 2: SetMapSource(MapSource.GoogleTerrain); break; case 3: SetMapSource(MapSource.GoogleHybrid); break; case 4: // OpenStreetMap SetMapSource(MapSource.OpenStreetMap); break; case 5: // OpenCycleMap SetMapSource(MapSource.OpenCycleMap); break; case 6: SetMapSource(MapSource.None); break; } }; actionSheet.ShowInView(View); } }
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; }