async void Handle_ItemTapped(object sender, Xamarin.Forms.ItemTappedEventArgs e) { var index = ViewModel.CourseItems.IndexOf(e.Item as CourseAgendaCellModel); await Map.AnimateCamera(CameraUpdateFactory.NewPositionZoom((Map.Pins[index].Position), 16), new TimeSpan(0, 0, 2)); listview.SelectedItem = null; }
private void MoveToRegion(MapMoveToRegionModel model) { var pos = new Position(model.Latitude, model.Longitude); map.MoveCamera(CameraUpdateFactory.NewPositionZoom(pos, 16)); map.MoveToRegion(MapSpan.FromCenterAndRadius(pos, Distance.FromMeters(model.RadiusInMeters))); }
public Mapa() { InitializeComponent(); Map map = new Map(); map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(-8.113097, -79.0315039), 15); map.VerticalOptions = LayoutOptions.FillAndExpand; MultasController mc = new MultasController(); List <Multa> multas = new List <Multa>(); multas = mc.data; foreach (var item in multas) { var pin = new Pin { Type = PinType.Place, Position = new Position(Convert.ToDouble(item.Latitud), Convert.ToDouble(item.Longitud)), Label = "Punto de Control", Address = item.Direccion }; map.Pins.Add(pin); } Content = map; }
public PinItemsSourcePage() { InitializeComponent(); BindingContext = new ViewModel(); _map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(startPosition, 3); }
public void OnNavigatingTo(NavigationParameters parameters) { if (!parameters.ContainsKey("id")) { return; } var id = Int32.Parse(parameters.GetValue <string>("id")); var fornecedor = new FornecedorService().GetFornecedor(id); var telefone = new TelefoneService().TelefonePrincipalDofornecedor(fornecedor.IdFornecedor); var posicaoInicial = new Position(fornecedor.Latitude, fornecedor.Longitude); var cameraUpdate = CameraUpdateFactory.NewPositionZoom(posicaoInicial, 15d); map.InitialCameraUpdate = cameraUpdate; var pinFornecedor = new Pin() { Label = fornecedor.NomeFantasia, Address = $"({telefone.CodigoArea}) {telefone.NumeroTelefone}", Position = posicaoInicial, IsVisible = true }; map.Pins.Add(pinFornecedor); }
//Handle the route button clicked event private void RouteButton_Clicked(object sender, EventArgs e) { double Latitude = Current.SelectedItem.Latitude + ((Current.CU.Latitude - Current.SelectedItem.Latitude) / 2); //Variable that stores the latitude point between the selectedItem it's latitude and the user it's latitude position double Longitude = Current.SelectedItem.Longitude + ((Current.CU.Longitude - Current.SelectedItem.Longitude) / 2); //Variable that stores the longitude point between the selectedItem it's longitude and the user it's longitude position double Zoom = 14; //zoom range: 2 - 21 Task.Run(() => { Device.BeginInvokeOnMainThread(async() => { await Finder.TranslateTo(0, 587.5, 200); Position FullRoutePosition = new Position(Latitude, Longitude); await Current.CustomMap.AnimateCamera(CameraUpdateFactory.NewPositionZoom(FullRoutePosition, Zoom), TimeSpan.FromSeconds(2.5)); //Animate the camera of the map to the FullRoute position of the user with a calculated zoom level and in a timespan of 2.5 seconds Thread.Sleep(2500); //Thread will stop for 2.5 seconds Current.UpdateCamera = true; //Allow camera updates Position LocationUser = new Position(Current.CU.Latitude, Current.CU.Longitude); await Current.CustomMap.AnimateCamera(CameraUpdateFactory.NewPositionZoom(LocationUser, 17.5), TimeSpan.FromSeconds(2.5)); //Animate the camera of the map to the position of the user with a zoom of 17.5 and in a timespan of 2.5 seconds await SubContent.FadeTo(0, 125); //Makes the SubContent of the current page fade out in 125 ms await Finder.TranslateTo(0, 400, 200); Current.FV.Children[0] = new DirectionsView(); //Changes the value of the grid FV to the new DirectionsView page }); }); }
public void OnNavigatedTo(NavigationParameters parameters) { if (parameters.ContainsKey("model") && parameters.ContainsKey("type")) { string type = (string)parameters["type"]; string bg = (string)parameters["background"]; BackgroundColor = Color.FromHex(bg); if (type.Equals("events")) { EventsList = (ObservableCollection <EventItem>)parameters["model"]; SetupEventsMarkers(); } else if (type.Equals("attractions")) { AttractionsList = (ObservableCollection <AttractionItem>)parameters["model"]; SetupAttractionsMarkers(); } else if (type.Equals("restaurants")) { RestaurantsList = (ObservableCollection <RestaurantItem>)parameters["model"]; SetupRestaurantsMarkers(); } mMap.PinClicked += (sender, e) => { mMap.MoveCamera(CameraUpdateFactory.NewPositionZoom( e.Pin.Position, 15d)); }; } }
protected virtual async void CameraChanged(object sender, CameraIdledEventArgs e) { if (isCameraStable) { var lat = map.CameraPosition.Target.Latitude; var lon = map.CameraPosition.Target.Longitude; var zoom = map.CameraPosition.Zoom; map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(lat, lon), zoom); PropertiesDictionary.Latitude = lat; PropertiesDictionary.Longitude = lon; PropertiesDictionary.Zoom = zoom; if (map.VisibleRegion != null) { PropertiesDictionary.Radius = map.VisibleRegion.Radius.Meters; } MessagingCenter.Send(this, "CameraChanged"); isCameraStable = false; await Task.Delay(TimeSpan.FromSeconds(0.5)); isCameraStable = true; MessagingCenter.Send(this, "IsMapIdled"); } }
public MainPage() { InitializeComponent(); map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(20.9735, 105.847), 14); map.UiSettings.ZoomGesturesEnabled = true; map.UiSettings.ZoomControlsEnabled = false; map.UiSettings.RotateGesturesEnabled = false; }
public MapPickerPage(LocationPickerType pickerType, GooglePlace selectedAddress = null) { InitializeComponent(); SelectedAddress = selectedAddress; PickerType = pickerType; #if __IOS__ if (App.Locator.DeviceService.IsIphoneX() == true) { TitleLabel.TranslationY = 35; BackButton.TranslationY = 10; } else { TitleLabel.TranslationY = 24; } #elif __ANDROID__ TitleLabel.TranslationY = 5; BackButton.TranslationY = -18; BackButton.TranslationX = -30; #endif SelectButton.Opacity = 0; MapView.UiSettings.ZoomControlsEnabled = false; MapView.MyLocationEnabled = true; MapView.CameraIdled += (sender, e) => { if (SelectButton.Opacity > 0) { LoadAddress(MapView.CameraPosition.Target.Latitude, MapView.CameraPosition.Target.Longitude); } }; if (SelectedAddress != null) { SelectButton.Opacity = 1; MapView.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(SelectedAddress.Latitude, SelectedAddress.Longitude), 20d); LoadAddress(SelectedAddress.Latitude, SelectedAddress.Longitude); } else if (!App.Locator.LocationHelper.lat.Equals(0.0)) { MapView.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(App.Locator.LocationHelper.lat, App.Locator.LocationHelper.lng), 20d); } if (PickerType == LocationPickerType.To) { TitleLabel.Text = AppResources.SelectToLocation; } else if (PickerType == LocationPickerType.From) { TitleLabel.Text = AppResources.SelectFromLocation; } }
// My location button draw current marker async void Handle_MyLocationButtonClicked(object sender, Xamarin.Forms.GoogleMaps.MyLocationButtonClickedEventArgs e) { if (IsBusy) { return; } IsBusy = true; try { if (CrossGeolocator.IsSupported && CrossGeolocator.Current.IsGeolocationEnabled) { var locator = CrossGeolocator.Current; locator.DesiredAccuracy = 50; var location = await locator.GetPositionAsync(new TimeSpan(0, 0, 6)); if (location != null) { var context = BindingContext as AgendaPageModel; if (Map.Pins.Contains(MyPin)) { Map.Pins.Remove(MyPin); } Map.Pins.Add(MyPin = new Pin() { Address = "", IsDraggable = false, Flat = true, Label = "Current Location", Type = PinType.SavedPin, IsVisible = true, Icon = BitmapDescriptorFactory.FromView(new BindingPinView("Me", Color.Transparent)), Position = new Position(location.Latitude, location.Longitude) }); await Map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(new Position(location.Latitude, location.Longitude), 12), new TimeSpan(0, 0, 3)); } await locator.StopListeningAsync(); } else { var response = await DisplayAlert(AppResources.Alert, AppResources.LocationEnableAlert, AppResources.Ok, AppResources.NotNow); } } catch (Exception) { } IsBusy = false; }
public CustomGoogleMap(IGeolocatorService geolocatorService) { _geolocatorService = geolocatorService; //var location = new Position(30.4, -97.7); var location = _geolocatorService.LastRecordedPosition; var cf = CameraUpdateFactory.NewPositionZoom(location, 13.0); this.InitialCameraUpdate = cf; }
public void EndDelineation() { map.Polygons.Clear(); map.Pins.Clear(); map.Pins.Append(PlotPins); map.Polygons.Append(PlotDelineations); RestorePins(); map.AnimateCamera(CameraUpdateFactory.NewPositionZoom(new Position(20, -100), 5), TimeSpan.FromSeconds(2)); }
private async void CloseButton_Clicked(object sender, EventArgs e) { await RootContent.FadeTo(0, 125); //Makes the RootContent of the current page fade out in 125 ms await Finder.TranslateTo(0, 400, 200); Current.FV.Children[0] = new RouteView(); //Changes the value of the grid FV to the new RouteView page Current.UpdateCamera = false; //Prevents the camera from updating when the postion changes Position LocationUser = new Position(Current.SelectedItem.Latitude, Current.SelectedItem.Longitude); await Current.CustomMap.AnimateCamera(CameraUpdateFactory.NewPositionZoom(LocationUser, 17.5), TimeSpan.FromSeconds(2.5)); //Animate the camera of the map to the selected position with a zoom of 17.5 and in a timespan of 2.5 seconds }
//Handle the close button clicked event private async void CloseButton_Clicked(object sender, EventArgs e) { await RootContent.FadeTo(0, 125); //Makes the RootContent of the current page fade out in 125 ms await Finder.TranslateTo(0, 400, 200); Current.FV.Children[0] = new MainView(); //Changes the value of the grid FV to the new MainView page Current.UpdateCamera = true; Position LocationUser = new Position(Current.CU.Latitude, Current.CU.Longitude); await Current.CustomMap.AnimateCamera(CameraUpdateFactory.NewPositionZoom(LocationUser, 17.5), TimeSpan.FromSeconds(2.5)); }
/*Change FinderView and go to selected place*/ public async void Place_Tapped(object sender, ItemTappedEventArgs e) { Current.SelectedItem = (Place)e.Item; //Stores the selected place it's data in the variable Current.SelectedItem await Finder.TranslateTo(0, 400, 200); //Makes the content of the current page fade out in 125 ms await MainViewContent.FadeTo(0, 150); Current.FV.Children[0] = new RouteView(); //Changes the value of the grid FV to the new RouteView page Current.UpdateCamera = false; //Prevents the camera from updating when the postion changes Position LocationTappedPlace = new Position(Current.SelectedItem.Latitude, Current.SelectedItem.Longitude); await Current.CustomMap.AnimateCamera(CameraUpdateFactory.NewPositionZoom(LocationTappedPlace, 17.5), TimeSpan.FromSeconds(2.5)); //Animate the camera of the map to the selected position with a zoom of 17.5 and in a timespan of 2.5 seconds }
public MapViewModel() { googleMapsApi = new GoogleMapsApiService(); Map = new Map { InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(-2.19d, -79.89d), 12d), MapType = MapType.Street, }; Map.UiSettings.ZoomControlsEnabled = false; RequestLocationServices(); Map.MapLongClicked += Map_MapLongClicked; Map.PinDragEnd += Map_PinDragEnd; GetPlacesCommand = new Command <string>(async(param) => await GetPlacesByName(param)); GetPlaceDetailCommand = new Command <GooglePlaceAutoCompletePrediction>(async(param) => await SetPlaceSelectedOnMap(param)); LoadRouteCommand = new Command(() => DrawRoute()); }
public override object ConvertFromInvariantString(string value) { var err = $@"{value} is invalid format. Expects are ""lat, lon"", ""lat, lon, zoom"", ""lat, lon, zoom, rotation"" and ""lat, lon, zoom, rotation, tilt"" "; var values = value.Split(','); if (values.Length < 2) { throw new ArgumentException(err); } var nums = new List <double>(); foreach (var v in values) { double ret; if (!double.TryParse(v, out ret)) { throw new ArgumentException(err); } nums.Add(ret); } if (nums.Count == 2) { return(CameraUpdateFactory.NewPosition(new Position(nums[0], nums[1]))); } if (nums.Count == 3) { return(CameraUpdateFactory.NewPositionZoom(new Position(nums[0], nums[1]), nums[2])); } if (nums.Count == 4) { return(CameraUpdateFactory.NewCameraPosition(new CameraPosition( new Position(nums[0], nums[1]), nums[2], nums[3]))); } return(CameraUpdateFactory.NewCameraPosition(new CameraPosition( new Position(nums[0], nums[1]), nums[2], nums[3], nums[4]))); }
async private Task UpdateCamera() { var lastLocation = await Geolocation.GetLastKnownLocationAsync(); if (lastLocation != null) { var lastPosition = new Position(lastLocation.Latitude, lastLocation.Longitude); LocationMap.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(lastPosition, 15); } else { var request = new GeolocationRequest(GeolocationAccuracy.Low); var currentLocation = await Geolocation.GetLocationAsync(request); var currentPosition = new Position(currentLocation.Latitude, currentLocation.Longitude); LocationMap.MoveToRegion(MapSpan.FromCenterAndRadius(currentPosition, Distance.FromMiles(0.1))); } }
protected override async void OnAppearing() { base.OnAppearing(); if (_firstStart) { _firstStart = false; if (Device.RuntimePlatform.Equals(Device.Android)) { await Task.Delay(500); // Для Андроида нужно немного подождать для корректной иницилизации компонента карты } if (await MyExtensions.CheckGPSPermissions(this)) { // иницилизация карты AirsMap.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(), 10d); } } }
async void MoveToCurrentLocation() { currentLocation = await Location.GetCurrentLocation(true); if (currentLocation != null) { if (currentPin != null && map.Pins.Contains(currentPin)) { map.Pins.Remove(currentPin); } map.Pins.Add(currentPin = new Pin() { Label = "Me", Position = new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude), Type = PinType.Place }); await map.MoveCamera(CameraUpdateFactory.NewPositionZoom(new Xamarin.Forms.GoogleMaps.Position(currentLocation.Latitude, currentLocation.Longitude), 12d)); } }
private async void LoadInitialPosition() { var position = await App.Locator.LocationHelper.GetLocation(true); if (position != null && MapView != null) { var pin = new Pin() { Label = "", Position = new Position(position.Latitude, position.Longitude) }; SelectButton.Opacity = 1; await MapView.AnimateCamera(CameraUpdateFactory.NewPositionZoom( pin.Position, 20d), TimeSpan.FromSeconds(0.01)); LoadAddress(position.Latitude, position.Longitude); } }
async void GetLastCachedLocation() { try { var Has_Permission = await Helpers.Permissions.CheckPermissionLocation(); if (!Has_Permission) { return; } if (CrossGeolocator.IsSupported && CrossGeolocator.Current.IsGeolocationEnabled) { var locator = CrossGeolocator.Current; var location = await locator.GetLastKnownLocationAsync(); if (location != null) { Map.Pins.Add(MyPin = new Pin() { Address = "", IsDraggable = false, Flat = true, Label = AppResources.CurrentLocation, IsVisible = true, Icon = BitmapDescriptorFactory.FromView(new BindingPinView(AppResources.Me, Color.Transparent)), Position = new Position(location.Latitude, location.Longitude) }); Map.InitialCameraUpdate = (CameraUpdateFactory.NewPositionZoom(new Position(location.Latitude, location.Longitude), 12d)); } else { Handle_MyLocationButtonClicked(null, null); } } } catch (Exception) { } }
public ProductPage(Product product, bool isEnabled) { InitializeComponent(); BindingContext = new ProductPageViewModel(product, isEnabled); // Disable the map if position is null or if the seller is online only if (App.Position == null || product.Seller.Contains(".com") || product.Seller.Contains("eBay")) { map.IsEnabled = false; map.IsVisible = false; } else { // Set the map to user's current location map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(App.Position.Latitude, App.Position.Longitude), 10d); // Search for nearby stores from the seller SearchNearby(product.Seller); } }
public ClockPage(IEventAggregator eventAggregator) { InitializeComponent(); _eventAggregator = eventAggregator; _mapMoveToRegionSubscriptionEventToken = _eventAggregator.GetEvent <MapMoveToRegionEvent>().Subscribe((pos) => MoveToRegion(pos), ThreadOption.UIThread); _mapSetPinSubscriptionEventToken = _eventAggregator.GetEvent <MapSetPinEvent>().Subscribe((pos) => SetPin(pos), ThreadOption.UIThread); _initialPosition = new Position(13.6862045, 120.885412); map.MoveCamera(CameraUpdateFactory.NewPositionZoom(_initialPosition, 20)); map.MoveToRegion(MapSpan.FromCenterAndRadius(_initialPosition, Distance.FromKilometers(13)), false); map.UiSettings.ZoomControlsEnabled = false; map.UiSettings.CompassEnabled = false; map.UiSettings.MyLocationButtonEnabled = false; map.UiSettings.ScrollGesturesEnabled = true; map.UiSettings.ZoomGesturesEnabled = true; map.UiSettings.TiltGesturesEnabled = false; map.PinDragEnd += Map_PinDragEnd; }
public void DrawMap() { Map map = new Map(); map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(Convert.ToDouble(multaDetail.Latitud), Convert.ToDouble(multaDetail.Longitud)), 15); map.VerticalOptions = LayoutOptions.FillAndExpand; map.HorizontalOptions = LayoutOptions.FillAndExpand; var pin = new Pin { Type = PinType.Place, Position = new Position(Convert.ToDouble(multaDetail.Latitud), Convert.ToDouble(multaDetail.Longitud)), Label = multaDetail.Placa, Address = multaDetail.Direccion }; map.Pins.Add(pin); ContenedorMapaDetalle.Children.Add(map); }
// My location to be displayed at first launch from cached location which is fast async void GetLastCachedLocation() { try { if (CrossGeolocator.IsSupported && CrossGeolocator.Current.IsGeolocationEnabled) { var locator = CrossGeolocator.Current; var location = await locator.GetLastKnownLocationAsync(); if (location != null) { Map.Pins.Add(MyPin = new Pin() { Address = "", IsDraggable = false, Flat = true, Label = "Current Location", Type = PinType.SavedPin, IsVisible = true, Icon = BitmapDescriptorFactory.FromView(new BindingPinView("Me", Color.Transparent)), Position = new Position(location.Latitude, location.Longitude) }); Map.InitialCameraUpdate = (CameraUpdateFactory.NewPositionZoom(new Position(location.Latitude, location.Longitude), 12d)); await locator.StopListeningAsync(); } else { Handle_MyLocationButtonClicked(null, null); } } } catch (Exception) { } }
public void SetupRestaurantsMarkers() { if (mMap == null) { return; } mMap.Pins.Clear(); foreach (RestaurantItem item in RestaurantsList) { System.Diagnostics.Debug.WriteLine("restaurants map count position: " + item.latitude + " , " + item.longitude); Pin eventlocation = new Pin() { Type = PinType.Generic, Label = item.name, Position = new Position(Double.Parse(item.longitude), Double.Parse(item.latitude)) }; mMap.Pins.Add(eventlocation); mMap.MoveCamera(CameraUpdateFactory.NewPositionZoom( eventlocation.Position, 13d)); } }
protected async override void BindingContextSet() { base.BindingContextSet(); var context = BindingContext as TTab; if (context == null || context.Customer.PartnerLatitude == 0 || context.Customer.PartnerLongitude == 0) { return; } var Has_Permission = await Helpers.Permissions.CheckPermissionLocation(); if (!Has_Permission) { return; } #region Map_Pins_Set map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(context.Customer.PartnerLatitude.HasValue ? context.Customer.PartnerLatitude.Value : 0, context.Customer.PartnerLongitude.HasValue ? context.Customer.PartnerLongitude.Value : 0), 12d); var pin = new Pin() { Address = context.Customer.ContactAddress, IsDraggable = true, Flat = true, Label = context.Customer.Name, Type = PinType.SavedPin, IsVisible = true, Position = new Position(context.Customer.PartnerLatitude.HasValue ? context.Customer.PartnerLatitude.Value : 0, context.Customer.PartnerLongitude.HasValue ? context.Customer.PartnerLongitude.Value : 0) }; map.Pins.Add(pin); #endregion }
public BindingPinViewPage() { InitializeComponent(); map.InitialCameraUpdate = CameraUpdateFactory.NewPositionZoom(new Position(35.71d, 139.81d), 12d); }