void SetMapPosition(CLLocation location, double bearing = -1) { try { if (mMapView == null) { return; } if (bearing == -1) { mMapView.Animate(CameraPosition.FromCamera(location.Coordinate.Latitude, location.Coordinate.Longitude, zoom: PortableLibrary.Constants.MAP_ZOOM_LEVEL)); } else { mMapView.Animate(CameraPosition.FromCamera(location.Coordinate.Latitude, location.Coordinate.Longitude, PortableLibrary.Constants.MAP_ZOOM_LEVEL, bearing, 0)); } if (markerMyLocation != null) { markerMyLocation.Position = new CLLocationCoordinate2D(location.Coordinate.Latitude, location.Coordinate.Longitude); } } catch (Exception ex) { ShowMessageBox(null, ex.Message); } }
void MoveCamera() { var camera = mapView.Camera; var zoom = Math.Max(camera.Zoom - 0.1f, 17.5f); var newCamera = CameraPosition.FromCamera(camera.Target, zoom, camera.Bearing + 10, camera.ViewingAngle + 10); mapView.Animate(newCamera); }
/// <summary> /// Views the did load. /// </summary> public override void ViewDidLoad() { base.ViewDidLoad(); unHideNavigationBar(this.NavigationController); setupNavigationBackground(this.NavigationController); this.NavigationController.NavigationBar.TintColor = UIColor.White; this.Title = "SOCIAL CIRCLE"; GlobalLocation globalLocation = new GlobalLocation(this, true); GradientBackgroundForButton(msgButton); msgButton.Layer.CornerRadius = 4; msgButton.ClipsToBounds = true; CornerRadius(35, addButton); NavigationController.NavigationBar.Translucent = false; if (!string.IsNullOrEmpty(Settings.UserLatSettings)) { GlobalLocation globalLocation_Local = new GlobalLocation(this, true); camera = CameraPosition.FromCamera(latitude: Convert.ToDouble(Settings.UserLatSettings), longitude: Convert.ToDouble(Settings.UserLongSettings), zoom: 12, bearing: 44, viewingAngle: 10); mapView = MapView.FromCamera(CGRect.Empty, camera); if (mapView != null) { mapView.MyLocationEnabled = true; mapView.Animate(camera); } } else { camera = CameraPosition.FromCamera(latitude: 30.7108, longitude: 76.7094, zoom: 12, bearing: 44, viewingAngle: 10); mapView = MapView.FromCamera(CGRect.Empty, camera); mapView.MyLocationEnabled = true; } var fitBoundsButton = new UIBarButtonItem("", UIBarButtonItemStyle.Plain, DidTapFitBounds); fitBoundsButton.Image = UIImage.FromBundle("Image-1"); NavigationItem.RightBarButtonItem = fitBoundsButton; customButton1.Frame = new CGRect(8, 5, 45, 45); customButton2.Frame = new CGRect(View.Frame.X + View.Frame.Width - 53, 5, 45, 45); customButton3.Frame = new CGRect(View.Frame.X + View.Frame.Width - 53, customButton2.Frame.Y + customButton2.Frame.Height + 5, 45, 45); msgButton.Frame = new CGRect(20, View.Frame.Height - 140, View.Frame.Width - 40, 45); addButton.Frame = new CGRect(View.Frame.X + View.Frame.Width - 80, View.Frame.Height - 230, addButton.Frame.Width, addButton.Frame.Height); mapView.Add(msgButton); mapView.Add(addButton); mapView.Add(customButton1); mapView.Add(customButton2); mapView.Add(customButton3); View = mapView; mapView.Delegate = new CustomMapDelegate(mapView); //Call Delegate of MapView markers = new List <Marker>(); // Initialize marker list HandleClicks(); //Button Clicks CreateCircle(); //Circle with static radius }
public override void ViewDidLoad() { base.ViewDidLoad(); var camera = CameraPosition.FromCamera(-37.81969, 144.966085, 4); mapView = MapView.FromCamera(CGRect.Empty, camera); var sydneyMarker = new Marker() { Position = new CLLocationCoordinate2D(-33.8683, 151.2086), Map = mapView }; melbourneMarker = new Marker() { Position = new CLLocationCoordinate2D(-37.81969, 144.966085), Map = mapView }; mapView.MarkerInfoWindow = (aMapView, aMarker) => { if (aMarker == melbourneMarker) { return(new UIImageView(UIImage.FromBundle("Icon"))); } return(null); }; mapView.TappedMarker = (aMapView, aMarker) => { // Animate to the marker CATransaction.Begin(); CATransaction.AnimationDuration = 3; // 3 second animation var cam = new CameraPosition(aMarker.Position, 8, 50, 60); mapView.Animate(cam); CATransaction.Commit(); // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to // fire. Also check that the marker isn't already selected so that the // InfoWindow doesn't close. if (aMarker == melbourneMarker && mapView.SelectedMarker != melbourneMarker) { return(false); } // The Tap has been handled so return YES return(true); }; View = mapView; }
/// <summary> /// Animates the camera. /// </summary> public void AnimateCamera() { GlobalLocation globalLocation_Local = new GlobalLocation(this, true); if (!string.IsNullOrEmpty(Settings.UserLatSettings)) { camera = CameraPosition.FromCamera(latitude: Convert.ToDouble(Settings.UserLatSettings), longitude: Convert.ToDouble(Settings.UserLongSettings), zoom: 12, bearing: 44, viewingAngle: 10); if (mapView != null) { mapView.MyLocationEnabled = true; mapView.Animate(camera); } } }
public async void GetAlertUsers() { double lat = 0; double lng = 0; try { lat = RacoonMap.pinLatitude; lng = RacoonMap.pinLongitutde; Xamarin.Forms.Maps.Position position = new Xamarin.Forms.Maps.Position(lat, lng); UIImage icon = UIImage.FromFile("pin.png"); var xamMarker = new Marker() { Title = RacoonMap.pinLabel, Position = new CLLocationCoordinate2D(lat, lng), AppearAnimation = MarkerAnimation.Pop, Icon = icon, Snippet = RacoonMap.pinAddress, }; xamMarker.Map = GoogleMapView; GoogleMapView.Animate(CameraUpdate.SetTarget(new CLLocationCoordinate2D(RacoonMap.pinLatitude, RacoonMap.pinLongitutde))); GoogleMapView.InfoTapped += GoogleMapView_InfoTapped; GoogleMapView.SelectedMarker = xamMarker; GoogleMapView.TappedMarker = (map, marker) => { GoogleMapView.MarkerInfoWindow = new GMSInfoFor(markerInfoWindow); return(false); }; } catch { } finally { } }
private bool TappedMarker(MapView mapView, Marker marker) { CATransaction.Begin(); CATransaction.AnimationDuration = 0.5; // 1 second animation var cam = new CameraPosition(marker.Position, 16, 0, 0); mapView.Animate(cam); CATransaction.Commit(); AppUtils.ShowChoiceDialog(this, "Remove Marker?", "Do you want to delete this marker?", "Yes", (mrk) => { mrk.Map = null; markers.Remove(mrk); MarkLocButton.Enabled = CheckThisLocationMarked(); UpdateText(); }, "No", (mrk) => { }, marker); return(true); }
public override void ObserveValue(NSString keyPath, NSObject ofObject, NSDictionary change, IntPtr context) { try { currentLocation = change.ObjectForKey(NSValue.ChangeNewKey) as CLLocation; if (!isFirst) { mapView.Animate(new CameraPosition(new CLLocationCoordinate2D(currentLocation.Coordinate.Latitude, currentLocation.Coordinate.Longitude), mapView.Camera.Zoom, mapView.Camera.Bearing, mapView.Camera.ViewingAngle)); } else { mapView.Camera = CameraPosition.FromCamera(currentLocation.Coordinate, 16.00f); isFirst = false; } CheckTollRoad(); } catch (Exception) { //TODO: Burası Sisteme Loglanıcak. } }
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 BanaYakinLokasyonlariGetir() { WebService webService = new WebService(); var Donus = webService.OkuGetir("locations"); if (Donus != null) { var aa = Donus.ToString(); mekanlar_list = Newtonsoft.Json.JsonConvert.DeserializeObject <List <Mekanlar_Location> >(Donus.ToString()); if (mekanlar_list.Count > 0) { InvokeOnMainThread(delegate() { if (mekanlar_list.Count > 0) { GetMap(Mapview); } for (int i = 0; i < mekanlar_list.Count; i++) { var xamMarker = new Marker() { Title = "", Snippet = "", Position = new CLLocationCoordinate2D(mekanlar_list[i].coordinateX, mekanlar_list[i].coordinateY), Map = mapView, Icon = UIImage.FromBundle("Images/mapmarkerrr.png"), }; OlusanMarkerlar.Add(xamMarker); } if (mekanlar_list.Count > 0) { mapView.SelectedMarker = OlusanMarkerlar[0]; var newCamera = CameraPosition.FromCamera(OlusanMarkerlar[0].Position, 10, mapView.Camera.Bearing + 10, mapView.Camera.ViewingAngle + 10); mapView.Animate(newCamera); this.mapView.TappedMarker = (map, marker) => { var id = OlusanMarkerlar.FindIndex(item => item == marker); try { var IndexConvert = Convert.ToInt32(id); Scrolll.SetContentOffset(new CGPoint(Noktalar[IndexConvert].Frame.X, 0), true); var PageeIndex = (nint)(Scrolll.ContentOffset.X / Scrolll.Frame.Width); Console.WriteLine("OK"); } catch { } return(false); }; } CreateScrollViews(); Scrolll.PagingEnabled = true; CustomLoading.Hide(); }); } else { CustomAlert.GetCustomAlert(GelenBase1, "Çevrenizde hiç lokasyon bulunamadı..."); CustomLoading.Hide(); } } else { CustomLoading.Hide(); } }
public override void LoadView() { base.LoadView(); CameraPosition camera = CameraPosition.FromCamera(latitude: 42.392262, longitude: -72.526992, zoom: 6); mapView = MapView.FromCamera(CGRect.Empty, camera); mapView.MyLocationEnabled = true; View = mapView; mapView.CoordinateLongPressed += HandleLongPress; /* var addButton = new UIBarButtonItem(UIBarButtonSystemItem.Add, DidTapAdd); var clearButton = new UIBarButtonItem("Clear Markers", UIBarButtonItemStyle.Plain, (o, s) => { mapView.Clear(); }); NavigationItem.RightBarButtonItems = new[] { addButton, clearButton }; */ mapView.TappedMarker = (aMapView, aMarker) => { // Animate to the marker var cam = new CameraPosition(aMarker.Position, 8, 50, 60); mapView.Animate(cam); UIAlertView alert = new UIAlertView(); alert.Title = "Are you sure you want to select this position as the landmarks position?"; alert.AddButton("Cancel"); alert.AddButton("OK"); alert.CancelButtonIndex = 0; alert.Message = " If yes, please click OK"; //alert.AlertViewStyle = UIAlertViewStyle.PlainTextInput; alert.Clicked += (object s, UIButtonEventArgs ev) => { // handle click event here if (ev.ButtonIndex != 0) { _selectPagePosition.Longitude = aMarker.Position.Longitude.ToString(); _selectPagePosition.Latitude = aMarker.Position.Latitude.ToString(); _selectPagePosition.NavigateBack(); } //var a = Page.Navigation.NavigationStack[0]; // user input will be in alert.GetTextField(0).Text; }; alert.Show(); // Melbourne marker has a InfoWindow so return NO to allow markerInfoWindow to // fire. Also check that the marker isn't already selected so that the // InfoWindow doesn't close. /*if (aMarker == melbourneMarker && mapView.SelectedMarker != melbourneMarker) { return false; }*/ // The Tap has been handled so return YES return true; }; }
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(); }
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; }
public void AnimateAlpha(float alpha, long duration = 250) { mapView.Animate().Alpha(alpha).SetDuration(duration).Start(); }