public AddressMapViewModel(IMvxNavigationService navigationService, IConnection connection, IMvxMessenger messenger, IPermissionDependency permissionDependency, IGoogleMapsApiService googleMapsApiService, IGoogleMapTableAccess googleMapTableAccess, IQuickMessageDependency quickMessageDependency) { _navigationService = navigationService; _connection = connection; _messenger = messenger; _permissionDependency = permissionDependency; _googleMapsApiService = googleMapsApiService; _googleMapTableAccess = googleMapTableAccess; _quickMessageDependency = quickMessageDependency; Title = "Address Book"; Init(); _token = _messenger.Subscribe <AddressResult>((addr) => { try { if (addr != null) { if (!AddedAddresses.Any(x => x.PlaceId == addr.Address.PlaceId)) { _googleMapTableAccess.Insert(addr.Address); AddedAddresses.Add(addr.Address); ExecuteSelect(addr.Address); } } } catch (Exception ex) { _quickMessageDependency.ShowToastMessage(ex.Message); } }); }
private async void ExecuteSelect(GoogleMapTables address) { try { if (address != null && Map != null) { var position = new Position(address.Latitude, address.Longitude); // Latitude, Longitude var pin = new Pin { Type = PinType.Place, Position = position, Label = "custom pin", Address = "custom detail info" }; Map.Pins.Clear(); Map.Pins.Add(pin); Map.MoveToRegion(MapSpan.FromCenterAndRadius(position, Distance.FromMiles(1))); await RaisePropertyChanged("Map"); } else if (Map == null) { if (_connection.IsConnected()) { await SetMap(); } throw new Exception("Map not accessible."); } else if (address == null) { throw new Exception("Address is empty."); } } catch (Exception ex) { _quickMessageDependency.ShowToastMessage(ex.Message); } }
async void ExecuteSearch() { try { if (!string.IsNullOrEmpty(SearchAddress)) { var res = await _googleMapsApiService.GetPlaces(SearchAddress); if (res.AutoCompletePlaces?.Count > 0) { PlacesResult = new List <GooglePlaceAutoCompletePrediction>(res.AutoCompletePlaces); } } else { PlacesResult = new List <GooglePlaceAutoCompletePrediction>(); } } catch (Exception ex) { _quickMessageDependency.ShowToastMessage(ex.Message); } }