private async void BoxSearch_SearchButtonPressed(object sender, EventArgs e) { SearchText = BoxSearch.Text ?? ""; if (await this.TextValidate(App.AppName, "Aceptar", new ValidateItem(SearchText, "Ingresa una dirección"))) { var geoCoder = new Xamarin.Forms.Maps.Geocoder(); var approximateLocations = await geoCoder.GetPositionsForAddressAsync(SearchText); if (approximateLocations.Count() > 0) { _search = true; GridMap.Children.Clear(); var location = approximateLocations.ElementAt(0); var map = new Xamarin.Forms.Maps.Map(Xamarin.Forms.Maps.MapSpan.FromCenterAndRadius(location, Xamarin.Forms.Maps.Distance.FromMiles(0.7))) { IsShowingUser = true, VerticalOptions = LayoutOptions.FillAndExpand }; map.Pins.Clear(); var pin = Pin(location, SearchText); map.Pins.Add(pin); GridMap.Children.Add(map); } } }
private async Task Inicializar(FirebaseClient _firebaseClient) { try { IsBusy = true; camiones = new ObservableCollection <DistribuidorFirebase>(); Camiones = new ObservableCollection <DistribuidorFirebase>(); geoCoder = new Xamarin.Forms.Maps.Geocoder(); Locations = new ObservableCollection <TKCustomMapPin>(); locations = new ObservableCollection <TKCustomMapPin>(); centerSearch = (MapSpan.FromCenterAndRadius((new TK.CustomMap.Position(-0.180653, -78.46783820000002)), Distance.FromMiles(2))); if (CrossConnectivity.Current.IsConnected) { _firebaseClient = new FirebaseClient(ElGAS_FIREBASE); Device.BeginInvokeOnMainThread(async() => { await loadParametros(); }); Task.Run(() => this.LoadVendedores()).Wait(); } IsBusy = false; } catch (Exception ex) { Debug.Write(ex.Message); } }
public MapaViewModel() { _firebaseClient = new FirebaseClient(ElGAS_FIREBASE); camiones = new ObservableCollection <DistribuidorFirebase>(); Camiones = new ObservableCollection <DistribuidorFirebase>(); geoCoder = new Xamarin.Forms.Maps.Geocoder(); Locations = new ObservableCollection <TKCustomMapPin>(); locations = new ObservableCollection <TKCustomMapPin>(); centerSearch = (MapSpan.FromCenterAndRadius((new TK.CustomMap.Position(0, 0)), Distance.FromMiles(.3))); Device.BeginInvokeOnMainThread(async() => { await loadParametros(); }); LoadVendedores(); }
/* * private void MyMap_MapClicked(object sender, TK.CustomMap.TKGenericEventArgs<TK.CustomMap.Position> e) * { * _pins.Clear(); * //if(MyMap.Pins != null) MyMap.Pins.ToList().Clear(); * var pin = new TKCustomMapPin * { * //Type = TKCustomMapPin.Place, * Position = e.Value, * Title = "Posición Actual" * //Label = "Posición Actual", * }; * * _pins.Add(pin); * // MyMap.Pins = _pins; * * }*/ async private void MyMap_PinDragEnd(object sender, TK.CustomMap.TKGenericEventArgs <TK.CustomMap.TKCustomMapPin> e) { double lat = e.Value.Position.Latitude; double lng = e.Value.Position.Longitude; Xamarin.Forms.Maps.Geocoder geoCoder = new Xamarin.Forms.Maps.Geocoder(); TK.CustomMap.Position position = new TK.CustomMap.Position(lat, lng); var vm = (MainViewModel)BindingContext; vm.Maps.Coordenadas = position.Latitude + "," + position.Longitude; var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude)); vm.Maps.Direccion = ""; foreach (var a in possibleAddresses) { vm.Maps.Direccion += a; break; } }
public StorePage (Store store) { dataStore = DependencyService.Get<IDataStore> (); Store = store; if (Store == null) { Store = new Store (); Store.MondayOpen = "9am"; Store.TuesdayOpen = "9am"; Store.WednesdayOpen = "9am"; Store.ThursdayOpen = "9am"; Store.FridayOpen = "9am"; Store.SaturdayOpen = "9am"; Store.SundayOpen = "12pm"; Store.MondayClose = "8pm"; Store.TuesdayClose = "8pm"; Store.WednesdayClose = "8pm"; Store.ThursdayClose = "8pm"; Store.FridayClose = "8pm"; Store.SaturdayClose = "8pm"; Store.SundayClose = "6pm"; isNew = true; } Title = isNew ? "New Store" : "Edit Store"; ToolbarItems.Add (new ToolbarItem { Text="Save", Command = new Command(async (obj)=> { Store.Name = name.Text.Trim(); Store.LocationHint = locationHint.Text.Trim(); Store.City = city.Text.Trim(); Store.PhoneNumber = phoneNumber.Text.Trim(); Store.Image = imageUrl.Text.Trim(); Store.StreetAddress = streetAddress.Text.Trim(); Store.State = state.Text.Trim(); Store.ZipCode = zipCode.Text.Trim(); Store.LocationCode = locationCode.Text.Trim(); Store.Country = country.Text.Trim(); double lat; double lng; var parse1 = double.TryParse(latitude.Text.Trim(), out lat); var parse2 = double.TryParse(longitude.Text.Trim(), out lng); Store.Longitude = lng; Store.Latitude = lat; Store.MondayOpen = mondayOpen.Text.Trim(); Store.MondayClose = mondayClose.Text.Trim(); Store.TuesdayOpen = tuesdayOpen.Text.Trim(); Store.TuesdayClose = tuesdayClose.Text.Trim(); Store.WednesdayOpen = wednesdayOpen.Text.Trim(); Store.WednesdayClose = wednesdayClose.Text.Trim(); Store.ThursdayOpen = thursdayOpen.Text.Trim(); Store.ThursdayClose = thursdayClose.Text.Trim(); Store.FridayOpen = fridayOpen.Text.Trim(); Store.FridayClose = fridayClose.Text.Trim(); Store.SaturdayOpen = saturdayOpen.Text.Trim(); Store.SaturdayClose = saturdayClose.Text.Trim(); Store.SundayOpen = sundayOpen.Text.Trim(); Store.SundayClose = sundayClose.Text.Trim(); bool isAnyPropEmpty = Store.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.GetValue(Store) is string && p.CanRead && p.CanWrite && p.Name != "State") // selecting only string props .Any(p => string.IsNullOrWhiteSpace((p.GetValue(Store) as string))); if(isAnyPropEmpty || !parse1 || !parse2) { await DisplayAlert("Not Valid", "Some fields are not valid, please check", "OK"); return; } Title = "SAVING..."; if(isNew) { await dataStore.AddStoreAsync(Store); } else { await dataStore.UpdateStoreAsync(Store); } await DisplayAlert("Saved", "Please refresh store list", "OK"); await Navigation.PopAsync(); }) }); Content = new TableView { HasUnevenRows = true, Intent = TableIntent.Form, Root = new TableRoot { new TableSection ("Information") { (name = new EntryCell {Label = "Name", Text = Store.Name}), (locationHint = new EntryCell {Label = "Location Hint", Text = Store.LocationHint}), (phoneNumber = new EntryCell {Label = "Phone Number", Text = Store.PhoneNumber, Placeholder ="555-555-5555"}), (locationCode = new EntryCell {Label = "Location Code", Text = Store.LocationCode}), }, new TableSection ("Image") { (imageUrl = new EntryCell { Label="Image URL", Text = Store.Image, Placeholder = ".png or .jpg image link" }), (refreshImage = new TextCell() { Text="Refresh Image" }), new ViewCell { View = (image = new Image { HeightRequest = 400, VerticalOptions = LayoutOptions.FillAndExpand }) } }, new TableSection ("Address") { (streetAddress = new EntryCell {Label = "Street Address", Text = Store.StreetAddress }), (city = new EntryCell {Label = "City", Text = Store.City }), (state = new EntryCell {Label = "State", Text = Store.State }), (zipCode = new EntryCell {Label = "Zipcode", Text = Store.ZipCode }), (country = new EntryCell{Label="Country", Text = Store.Country}), (detectLatLong = new TextCell() { Text="Detect Lat/Long" }), (latitude = new TextCell {Text = Store.Latitude.ToString() }), (longitude = new TextCell {Text = Store.Longitude.ToString() }), }, new TableSection ("Hours") { (mondayOpen = new EntryCell {Label = "Monday Open", Text = Store.MondayOpen}), (mondayClose = new EntryCell {Label = "Monday Close", Text = Store.MondayClose}), (tuesdayOpen = new EntryCell {Label = "Tuesday Open", Text = Store.TuesdayOpen}), (tuesdayClose = new EntryCell {Label = "Tuesday Close", Text = Store.TuesdayClose}), (wednesdayOpen = new EntryCell {Label = "Wedneday Open", Text = Store.WednesdayOpen}), (wednesdayClose = new EntryCell {Label = "Wedneday Close", Text = Store.WednesdayClose}), (thursdayOpen = new EntryCell {Label = "Thursday Open", Text = Store.ThursdayOpen}), (thursdayClose = new EntryCell {Label = "Thursday Close", Text = Store.ThursdayClose}), (fridayOpen = new EntryCell {Label = "Friday Open", Text = Store.FridayOpen}), (fridayClose = new EntryCell {Label = "Friday Close", Text = Store.FridayClose}), (saturdayOpen = new EntryCell {Label = "Saturday Open", Text = Store.SaturdayOpen}), (saturdayClose =new EntryCell {Label = "Saturday Close", Text = Store.SaturdayClose}), (sundayOpen = new EntryCell {Label = "Sunday Open", Text = Store.SundayOpen}), (sundayClose = new EntryCell {Label = "Sunday Close", Text = Store.SundayClose}), }, }, }; refreshImage.Tapped += (sender, e) => { image.Source = ImageSource.FromUri(new Uri(imageUrl.Text)); }; detectLatLong.Tapped += async (sender, e) => { var coder = new Xamarin.Forms.Maps.Geocoder(); var oldTitle = Title; Title = "Please wait..."; var locations = await coder.GetPositionsForAddressAsync(streetAddress.Text + " " + city.Text + ", " + state.Text + " " + zipCode.Text + " " + country.Text); Title = oldTitle; foreach(var location in locations) { latitude.Text = location.Latitude.ToString(); longitude.Text = location.Longitude.ToString(); break; } }; SetBinding (Page.IsBusyProperty, new Binding("IsBusy")); }
public StorePage(Store store) { dataStore = DependencyService.Get <IDataStore> (); Store = store; if (Store == null) { Store = new Store(); Store.MondayOpen = "9am"; Store.TuesdayOpen = "9am"; Store.WednesdayOpen = "9am"; Store.ThursdayOpen = "9am"; Store.FridayOpen = "9am"; Store.SaturdayOpen = "9am"; Store.SundayOpen = "12pm"; Store.MondayClose = "8pm"; Store.TuesdayClose = "8pm"; Store.WednesdayClose = "8pm"; Store.ThursdayClose = "8pm"; Store.FridayClose = "8pm"; Store.SaturdayClose = "8pm"; Store.SundayClose = "6pm"; isNew = true; } Title = isNew ? "New Store" : "Edit Store"; ToolbarItems.Add(new ToolbarItem { Text = "Save", Command = new Command(async(obj) => { Store.Name = name.Text.Trim(); Store.LocationHint = locationHint.Text.Trim(); Store.City = city.Text.Trim(); Store.PhoneNumber = phoneNumber.Text.Trim(); Store.Image = imageUrl.Text.Trim(); Store.StreetAddress = streetAddress.Text.Trim(); Store.State = state.Text.Trim(); Store.ZipCode = zipCode.Text.Trim(); Store.LocationCode = locationCode.Text.Trim(); Store.Country = country.Text.Trim(); double lat; double lng; var parse1 = double.TryParse(latitude.Text.Trim(), out lat); var parse2 = double.TryParse(longitude.Text.Trim(), out lng); Store.Longitude = lng; Store.Latitude = lat; Store.MondayOpen = mondayOpen.Text.Trim(); Store.MondayClose = mondayClose.Text.Trim(); Store.TuesdayOpen = tuesdayOpen.Text.Trim(); Store.TuesdayClose = tuesdayClose.Text.Trim(); Store.WednesdayOpen = wednesdayOpen.Text.Trim(); Store.WednesdayClose = wednesdayClose.Text.Trim(); Store.ThursdayOpen = thursdayOpen.Text.Trim(); Store.ThursdayClose = thursdayClose.Text.Trim(); Store.FridayOpen = fridayOpen.Text.Trim(); Store.FridayClose = fridayClose.Text.Trim(); Store.SaturdayOpen = saturdayOpen.Text.Trim(); Store.SaturdayClose = saturdayClose.Text.Trim(); Store.SundayOpen = sundayOpen.Text.Trim(); Store.SundayClose = sundayClose.Text.Trim(); bool isAnyPropEmpty = Store.GetType().GetTypeInfo().DeclaredProperties .Where(p => p.GetValue(Store) is string && p.CanRead && p.CanWrite && p.Name != "State") // selecting only string props .Any(p => string.IsNullOrWhiteSpace((p.GetValue(Store) as string))); if (isAnyPropEmpty || !parse1 || !parse2) { await DisplayAlert("Not Valid", "Some fields are not valid, please check", "OK"); return; } Title = "SAVING..."; if (isNew) { await dataStore.AddStoreAsync(Store); } else { await dataStore.UpdateStoreAsync(Store); } await DisplayAlert("Saved", "Please refresh store list", "OK"); await Navigation.PopAsync(); }) }); Content = new TableView { HasUnevenRows = true, Intent = TableIntent.Form, Root = new TableRoot { new TableSection("Information") { (name = new EntryCell { Label = "Name", Text = Store.Name }), (locationHint = new EntryCell { Label = "Location Hint", Text = Store.LocationHint }), (phoneNumber = new EntryCell { Label = "Phone Number", Text = Store.PhoneNumber, Placeholder = "555-555-5555" }), (locationCode = new EntryCell { Label = "Location Code", Text = Store.LocationCode }), }, new TableSection("Image") { (imageUrl = new EntryCell { Label = "Image URL", Text = Store.Image, Placeholder = ".png or .jpg image link" }), (refreshImage = new TextCell() { Text = "Refresh Image" }), new ViewCell { View = (image = new Image { HeightRequest = 400, VerticalOptions = LayoutOptions.FillAndExpand }) } }, new TableSection("Address") { (streetAddress = new EntryCell { Label = "Street Address", Text = Store.StreetAddress }), (city = new EntryCell { Label = "City", Text = Store.City }), (state = new EntryCell { Label = "State", Text = Store.State }), (zipCode = new EntryCell { Label = "Zipcode", Text = Store.ZipCode }), (country = new EntryCell { Label = "Country", Text = Store.Country }), (detectLatLong = new TextCell() { Text = "Detect Lat/Long" }), (latitude = new TextCell { Text = Store.Latitude.ToString() }), (longitude = new TextCell { Text = Store.Longitude.ToString() }), }, new TableSection("Hours") { (mondayOpen = new EntryCell { Label = "Monday Open", Text = Store.MondayOpen }), (mondayClose = new EntryCell { Label = "Monday Close", Text = Store.MondayClose }), (tuesdayOpen = new EntryCell { Label = "Tuesday Open", Text = Store.TuesdayOpen }), (tuesdayClose = new EntryCell { Label = "Tuesday Close", Text = Store.TuesdayClose }), (wednesdayOpen = new EntryCell { Label = "Wedneday Open", Text = Store.WednesdayOpen }), (wednesdayClose = new EntryCell { Label = "Wedneday Close", Text = Store.WednesdayClose }), (thursdayOpen = new EntryCell { Label = "Thursday Open", Text = Store.ThursdayOpen }), (thursdayClose = new EntryCell { Label = "Thursday Close", Text = Store.ThursdayClose }), (fridayOpen = new EntryCell { Label = "Friday Open", Text = Store.FridayOpen }), (fridayClose = new EntryCell { Label = "Friday Close", Text = Store.FridayClose }), (saturdayOpen = new EntryCell { Label = "Saturday Open", Text = Store.SaturdayOpen }), (saturdayClose = new EntryCell { Label = "Saturday Close", Text = Store.SaturdayClose }), (sundayOpen = new EntryCell { Label = "Sunday Open", Text = Store.SundayOpen }), (sundayClose = new EntryCell { Label = "Sunday Close", Text = Store.SundayClose }), }, }, }; refreshImage.Tapped += (sender, e) => { image.Source = ImageSource.FromUri(new Uri(imageUrl.Text)); }; detectLatLong.Tapped += async(sender, e) => { var coder = new Xamarin.Forms.Maps.Geocoder(); var oldTitle = Title; Title = "Please wait..."; var locations = await coder.GetPositionsForAddressAsync(streetAddress.Text + " " + city.Text + ", " + state.Text + " " + zipCode.Text + " " + country.Text); Title = oldTitle; foreach (var location in locations) { latitude.Text = location.Latitude.ToString(); longitude.Text = location.Longitude.ToString(); break; } }; SetBinding(Page.IsBusyProperty, new Binding("IsBusy")); }
private async void loadCurrentPosition(bool fromButton) { //if (fromButton) //{ await Task.Delay(1500); //} if (!this.IsVisible) { return; } try { var status = await CrossPermissions.Current.CheckPermissionStatusAsync(Permission.Location); if (status != PermissionStatus.Granted) { if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(Permission.Location)) { await DisplayAlert("Need location", "Gunna need that location", "OK"); } var results = await CrossPermissions.Current.RequestPermissionsAsync(Permission.Location); //Best practice to always check that the key exists if (results.ContainsKey(Permission.Location)) { status = results[Permission.Location]; } } if (status == PermissionStatus.Granted) { CancellationTokenSource ctx = new CancellationTokenSource(); var locator = CrossGeolocator.Current; //CrossGeolocator.Current.PositionChanged += CrossGeolocator_Current_PositionChanged; locator.DesiredAccuracy = 15; if (locator.IsGeolocationAvailable && locator.IsGeolocationEnabled) { var location = await locator.GetPositionAsync(TimeSpan.FromSeconds(10)); TK.CustomMap.Position position = new TK.CustomMap.Position(location.Latitude, location.Longitude); // MyMap.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.25))); _pins.Clear(); var pin = new TKCustomMapPin { IsVisible = true, IsDraggable = true, //Type = TKCustomMapPin.Place, Position = position, Title = "Posición Actual" //Label = "Posición Actual", }; _pins.Add(pin); if (MyMap.Pins == null) { MyMap.Pins = _pins; } MyMap.MoveToMapRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(0.25))); Xamarin.Forms.Maps.Geocoder geoCoder = new Xamarin.Forms.Maps.Geocoder(); var vm = (MainViewModel)BindingContext; vm.Maps.Coordenadas = position.Latitude + "," + position.Longitude; var possibleAddresses = await geoCoder.GetAddressesForPositionAsync(new Xamarin.Forms.Maps.Position(position.Latitude, position.Longitude)); vm.Maps.Direccion = ""; foreach (var a in possibleAddresses) { vm.Maps.Direccion += a; break; } } } else if (status != PermissionStatus.Unknown) { await DisplayAlert("Localización denegada", "No se puede continuar, intentar nuevamente.", "OK"); } } catch (Exception ex) { } }
public DetalleViewModel(ComprasRequest comprasRequest) { try { EstadoPedido = ""; Compra = comprasRequest; geoCoder = new Xamarin.Forms.Maps.Geocoder(); Point p = new Point(0.48, 0.96); Locations = new ObservableCollection <TKCustomMapPin>(); locations = new ObservableCollection <TKCustomMapPin>(); Locations.Clear(); centerSearch = (MapSpan.FromCenterAndRadius((new TK.CustomMap.Position((double)Compra.Latitud, (double)Compra.Longitud)), Distance.FromMiles(.5))); Locations.Add(new TKCustomMapPin { Image = "casa", Position = new TK.CustomMap.Position((double)Compra.Latitud, (double)Compra.Longitud), Anchor = p, ShowCallout = true, }); switch (comprasRequest.Estado) { case -1: EstadoPedido = "Cancelado"; isCancelable = false; break; case 0: EstadoPedido = "No atendido"; isCancelable = true; break; case 1: EstadoPedido = "Pendiente"; isCancelable = true; break; case 2: EstadoPedido = "Entregado"; isCancelable = false; break; } var fecha = TimeZoneInfo.ConvertTime(comprasRequest.FechaPedido.Value, TimeZoneInfo.Local); FechaCompra = fecha.ToString("yyyy-MM-dd") + " " + comprasRequest.FechaPedido.Value.ToShortTimeString(); CantidadCompra = Compra.Cantidad.ToString(); ValorCompra = Compra.ValorTotal.ToString(); ObtenerDireccion((double)Compra.Latitud, (double)Compra.Longitud); } catch (Exception ex) { Debug.WriteLine(ex.Message); throw; } }