public void RequestAllMunicipalities_CallMunicipalitiesRepo()
        {
            PlacesService service = GetService();
            var           result  = service.GetAllMunicipalities();

            _municipalityRepoMock.Verify(m => m.GetMunicipalities(), Times.Once);
        }
        public void RequestAllMunicipalities_GetAllMunicipalities()
        {
            PlacesService service = GetService();
            var           result  = service.GetAllMunicipalities();

            Assert.IsInstanceOfType(result, typeof(Task <List <Municipality> >));
        }
        /// <summary>
        /// Obtains a list of places within a 10 meters radius of the specified address
        /// </summary>
        /// <param name="pAddress">Address of search</param>
        /// <returns></returns>
        public List <dynamic> PlacesByAddress(string pAddress)
        {
            PlacesRequest request = new TextSearchRequest()
            {
                Query  = pAddress,
                Radius = 10
            };

            PlacesResponse response    = new PlacesService().GetResponse(request);
            List <dynamic> foundPlaces = new List <dynamic>();

            if (response.Status == ServiceResponseStatus.Ok)
            {
                foreach (PlacesResult result in response.Results)
                {
                    dynamic place = new ExpandoObject();
                    place.Id      = result.PlaceId;
                    place.name    = result.Name;
                    place.address = result.FormattedAddress;
                    place.type    = new List <string>();
                    foreach (PlaceType type in result.Types)
                    {
                        place.type.Add(type.ToString());
                    }
                    place.rating = result.Rating;
                    place.photo  = result.Icon;
                    foundPlaces.Add(place);
                }
                return(foundPlaces);
            }
            else
            {
                return(null);
            }
        }
Beispiel #4
0
        public async Task InitializePlacesAsync()
        {
            var service = new PlacesService();
            var places  = await service.GetAllPlaces();

            Places = new ObservableCollection <Place>(places);
        }
Beispiel #5
0
        public MainPage()
        {
            this.InitializeComponent();

            availableRideTypes = new List <RideType>();

            geolocator = new Geolocator();
            geolocator.AllowFallbackToConsentlessPositions();
            geolocator.ReportInterval   = (uint)TimeSpan.FromSeconds(15).TotalSeconds;
            geolocator.PositionChanged += Geolocator_PositionChanged;

            driverList = new List <MapElement>();

            map.MapServiceToken          = Secrets.MapToken;
            map.BusinessLandmarksVisible = true;
            //map.LandmarksVisible = true;
            //map.PedestrianFeaturesVisible = true;
            //map.TrafficFlowVisible = true;
            //map.TransitFeaturesVisible = true;

            placesService       = new PlacesService();
            placeDetailsService = new PlaceDetailsService();
            addressToId         = new Dictionary <string, string>();
            reverseGeocode      = true;
            loaded = false;
        }
Beispiel #6
0
 public void Init(PlacesService placesService, ViewportService viewportService, SignalBus signalBus, Place place)
 {
     _placesService       = placesService;
     this.viewportService = viewportService;
     _signalBus           = signalBus;
     _place = place;
 }
Beispiel #7
0
        private async void AutoComplete()
        {
            OnPrepareOptionsMenu(actionBarMenu);
            actionBarMenu.FindItem(Resource.Id.action_add_to_fav).SetVisible(false);

            try
            {
                MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                // just dont autocomplete
                if (mapFragment.MyLocation == null)
                {
                    return;
                }

                List <Prediction> predictions = await PlacesService.GetSearchQueryPredictions(
                    searchTextView.Text, mapFragment.MyLocation);

                AWidget.ArrayAdapter adapter = new AWidget.ArrayAdapter <string>(
                    this, Android.Resource.Layout.SimpleDropDownItem1Line, predictions.Select(x => x.description).ToArray());

                searchTextView.Adapter = adapter;
                adapter.NotifyDataSetChanged();
            }
            catch (ApiCallException)
            {
            }
            catch (QueryAutoCompleteException)
            {
            }
        }
Beispiel #8
0
        private async Task GetPlacesByAverageVariationPourcentage()
        {
            ObservableCollection <ExpensesGestionModel> listGestionModel = new ObservableCollection <ExpensesGestionModel>();
            ExpensesGestionModel gestionModel;
            var service = new PlacesService();

            places = await service.GetPlacesByAverageVariationPourcentage(PourcentageAverageVariation);

            foreach (Place place in places)
            {
                gestionModel = new ExpensesGestionModel()
                {
                    IdModel    = place.PlaceId,
                    Average    = place.AverageAmount,
                    Name       = place.Name,
                    IsCategory = false
                };
                listGestionModel.Add(gestionModel);
            }
            ExpensesModels = listGestionModel;

            if (listGestionModel.Count == 0)
            {
                var loader = new ResourceLoader();
                ShowMessageDialog(loader.GetString("expensesGestionPlaceError"));
            }
        }
Beispiel #9
0
        private async void ExecuteLoadDataCommand(object obj)
        {
            IsBusy = true;
            try
            {
                Cars.Clear();

                var task1 = CarsService.GetCarsAsync();
                var task2 = PlacesService.GetPlacesAsync();
                foreach (var car in await task1)
                {
                    Cars.Add(car);
                }
                foreach (var place in await task2)
                {
                    if (!place.occupied)
                    {
                        Places.Add(place);
                    }
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                await Application.Current.MainPage.DisplayAlert("BŁĄD", "Nie udało się wczytać samochodów", "ANULUJ");
            }
            finally
            {
                IsBusy = false;
            }
        }
        private PlacesService GetService()
        {
            _regionRepoMock             = new Mock <IRegionRepo>();
            _regionMunicipalityRepoMock = new Mock <IRegionMunicipalitiesRepo>();
            _municipalityRepoMock       = new Mock <IMunicipalityRepo>();
            var res = new PlacesService(_regionRepoMock.Object, _municipalityRepoMock.Object, _regionMunicipalityRepoMock.Object);

            return(res);
        }
        public void ExceptionIsThrownIfApikeyIsNotProvided()
        {
            var request = new AutocompleteRequest()
            {
                Sensor = false,
                Input  = "London"
            };

            var response = new PlacesService().GetAutocompleteResponse(request);
        }
        public async Task UpdatePlaceAsync()
        {
            string error = _dataValidation.PlaceDataValidation(CurrentPlace);

            if (error == null)
            {
                var service = new PlacesService();
                error = await service.UpdatePlace(CurrentPlace);
            }
            ShowMessageDialog(error);
        }
Beispiel #13
0
        private async Task DeletePlace()
        {
            var msgDialog = new MessageDialog(String.Empty);

            if (CanExecute())
            {
                var service = new PlacesService();
                var error   = await service.DeletePlace(SelectedPlace.PlaceId);

                ShowMessageDialog(error);
            }
        }
        public async Task AddPlaceAsync()
        {
            NewPlace.CategoryId = SelectedCategory.CategoryId;

            string error = _dataValidation.PlaceDataValidation(NewPlace);

            if (error == null)
            {
                var service = new PlacesService();
                error = await service.AddPlace(NewPlace);
            }
            ShowMessageDialog(error);
        }
		public void Calling_PlacesServices_WithoutGeo_Should_ReturnListOfPlacesWithoutGeo ()
		{
			// Arrange
				
			// Act
			var service = new PlacesService (Config.AccessKey, Config.SecretKey);
			service.IncludeCoordinates = false;
			var places = service.GetPlaces ();
						
			// Assert
			Assert.Greater(places.Count, 0);
			Assert.IsTrue (places.All (x => x.Geography.Coordinates == null));			
		}
		public void Calling_PlacesServices_Should_ReturnListOfPlaces ()
		{
			// Arrange			
							
			// Act			
			var service = new PlacesService (Config.AccessKey, Config.SecretKey);
			var places = service.GetPlaces ();
			
			// Assert
			Assert.Greater(places.Count, 0);
			Assert.IsTrue (places.Any (x => x.Geography.Coordinates.Latitude > 0.0m));
			Assert.IsTrue (places.Any (x => x.Geography.Coordinates.Longitude > 0.0m));
		}
Beispiel #17
0
        public void Calling_PlacesServices_Should_ReturnListOfPlaces()
        {
            // Arrange

            // Act
            var service = new PlacesService(Config.AccessKey, Config.SecretKey);
            var places  = service.GetPlaces();

            // Assert
            Assert.Greater(places.Count, 0);
            Assert.IsTrue(places.Any(x => x.Geography.Coordinates.Latitude > 0.0m));
            Assert.IsTrue(places.Any(x => x.Geography.Coordinates.Longitude > 0.0m));
        }
Beispiel #18
0
        public void Calling_PlacesServices_WithoutGeo_Should_ReturnListOfPlacesWithoutGeo()
        {
            // Arrange

            // Act
            var service = new PlacesService(Config.AccessKey, Config.SecretKey);

            service.IncludeCoordinates = false;
            var places = service.GetPlaces();

            // Assert
            Assert.Greater(places.Count, 0);
            Assert.IsTrue(places.All(x => x.Geography.Coordinates == null));
        }
        public void ResponseIsNotNull()
        {
            var request = new AutocompleteRequest()
            {
                Sensor = false,
                Input  = "London"
            };

            var service = new PlacesService();
            AutocompleteResponse response = null;

            response = service.GetAutocompleteResponse(request);

            Assert.IsNotNull(response);
        }
        public string GetNearbyPlaceName(VehiclePoint point)
        {
            var           result        = "";
            GoogleSigned  VehicleApiKey = new GoogleSigned("AIzaSyC_iHzls7OqrC2d0OVUERemIyKS8h9BTUE");
            var           service       = new PlacesService(VehicleApiKey);
            PlacesRequest request       = new NearbySearchRequest()
            {
                Location = new LatLng(point.X, point.Y),
            };
            PlacesResponse response = service.GetResponse(request);

            if (response.Results != null && response.Results.Count() > 0)
            {
                result = response.Results.FirstOrDefault().Name;
            }
            return(result);
        }
        public void ResponseWith_Types_And_Places()
        {
            var request = new AutocompleteRequest()
            {
                Sensor     = false,
                Input      = "SK4 5DA",
                Regions    = true,
                Components = "UK"
            };

            var service = new PlacesService();
            AutocompleteResponse response = null;

            response = service.GetAutocompleteResponse(request);

            Assert.IsNotNull(response);
            Assert.IsTrue(response.Predictions.Length > 0);
            Assert.IsTrue(response.Status == ServiceResponseStatus.Ok);
        }
Beispiel #22
0
        public async Task Location_of_some_airports_can_be_determined(string code, Location expectedLocation)
        {
            // Arrange

            var httpClient = new HttpClient
            {
                BaseAddress = new Uri("https://places-dev.cteleport.com")
            };

            IAirportLocator locator     = new PlacesService(httpClient, new PolicyRegistry());
            var             airportCode = new AirportCode(code);

            // Act

            var location = await locator.GetLocationAsync(airportCode);

            // Assert
            Assert.Equal(expectedLocation, location);
        }
Beispiel #23
0
        public void PlacesTest_Nearby()
        {
            PlacesRequest request = new NearbySearchRequest()
            {
                Location = new LatLng(40.741895, -73.989308),
                Radius   = 10000,
                Sensor   = false
            };
            PlacesResponse response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(2000);

            // setting the PageToken value should result in valid request
            request = new NearbySearchRequest()
            {
                Location  = new LatLng(40.741895, -73.989308),
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(1100);

            // setting an invalid page token should result in InvalidRequest status
            request = new NearbySearchRequest()
            {
                Location  = new LatLng(40.741895, -73.989308),
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken + "A"                 // invalid token
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.InvalidRequest, response.Status);
        }
Beispiel #24
0
        public void PlacesTest_Text()
        {
            PlacesRequest request = new TextSearchRequest()
            {
                Query  = "New York, NY",
                Radius = 10000,
                Sensor = false
            };
            PlacesResponse response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(2000);

            // setting the PageToken value should result in valid request
            request = new TextSearchRequest()
            {
                Query     = "New York, NY",
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);

            // Google requires a delay before resending page token value
            Thread.Sleep(1100);

            // setting an invalid page token should result in InvalidRequest status
            request = new TextSearchRequest()
            {
                Query     = "New York, NY",
                Radius    = 10000,
                Sensor    = false,
                PageToken = response.NextPageToken + "A"                 // invalid token
            };
            response = new PlacesService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.InvalidRequest, response.Status);
        }
        /// <summary>
        /// Obtains a list of places within a 10 meters radius of the specified latitude and longitude
        /// </summary>
        /// <param name="pLatitude">Latitude</param>
        /// <param name="pLongitude">Longitude</param>
        /// <returns></returns>
        public List <dynamic> PlacesByCoordinates(double pLatitude, double pLongitude)
        {
            PlacesRequest request = new NearbySearchRequest()
            {
                Location = new LatLng(pLatitude, pLongitude),
                Radius   = 10
            };

            PlacesResponse response    = new PlacesService().GetResponse(request);
            List <dynamic> foundPlaces = new List <dynamic>();

            if (response.Status == ServiceResponseStatus.Ok)
            {
                foreach (PlacesResult result in response.Results)
                {
                    dynamic place = new ExpandoObject();
                    place.placeID = result.PlaceId;
                    place.name    = result.Name;
                    place.address = result.FormattedAddress;
                    place.type    = new List <string>();
                    foreach (PlaceType type in result.Types)
                    {
                        place.type.Add(type.ToString());
                    }
                    place.rating = result.Rating;
                    place.photo  = result.Icon;
                    foundPlaces.Add(place);
                }

                return(foundPlaces);
            }
            else
            {
                return(null);
            }
        }
Beispiel #26
0
 public GooglePlacesTests()
 {
     fixture = new PlacesService(GOOGLE_PLACES_API_KEY);
 }
        private async Task GetBestPlace()
        {
            var service = new PlacesService();

            BestPlace = await service.GetPlaceWithHighestNumberOfTransactions(NbDaysSelected);
        }
 private async void SearchTextAsync(string text)
 {
     Places         = new ObservableCollection <Place>(await PlacesService.GetPlacesAsync(text));
     IsLableVisible = Places.Count == 0;
 }
Beispiel #29
0
        public static void Run(object obj)
        {
            object[] objs = (object[])obj;
            MainForm form = (MainForm)objs[0];
            String   inp  = (String)objs[1];
            String   outp = (String)objs[2];

            try
            {
                form.UpdateText("Start loading file [ " + inp + " ]");
                StreamReader input  = new StreamReader(inp);
                StreamWriter output = new StreamWriter(outp);
                String[]     cvsformat;
                form.UpdateLog("Start loading file [ " + inp + " ]");
                while (!input.EndOfStream)
                {
                    cvsformat = input.ReadLine().Split(',');
                    busStop.Add(cvsformat[1]);
                    String addr = cvsformat[2];
                    int    h    = addr.IndexOf("巷");
                    int    i    = addr.IndexOf("弄");
                    int    j    = addr.IndexOf("號");
                    int    k    = addr.IndexOf("段");

                    if (j != -1)
                    {
                        addr = addr.Substring(0, j + 1);
                    }
                    else if (i != -1)
                    {
                        addr = addr.Substring(0, i + 1);
                    }
                    else if (h != -1)
                    {
                        addr = addr.Substring(0, h + 1);
                    }
                    else if (k != -1)
                    {
                        addr = addr.Substring(0, k + 1);
                    }
                    busStopAddress.Add(addr);
                }
                form.UpdateLog("Loading file [ " + inp + " ] finished");

                form.UpdateText("Start search address by Google Map");
                form.UpdateLog("Start search address by Google Map");
                Regex reg = new Regex("台北市(?<block>.{2})區");
                GoogleSigned.AssignAllServices(new GoogleSigned("AIzaSyCHjm9IB5R9kVBD3j_9dIuyVs_AKtVCA7s"));
                for (int i = 0; i < busStop.Count; i++)
                {
                    String b = "NOT FOUND";
                    form.UpdateText("Search " + busStop[i]);
                    if (busStopAddress[i] == "")
                    {
                        form.UpdateLog(i + " [ " + busStop[i] + " ] : " + b);
                        output.WriteLine((i + 1) + "," + b + "," + busStop[i]);
                        continue;
                    }
                    TextSearchRequest request = new TextSearchRequest();
                    request.Query = busStopAddress[i];
                    if (busStopAddress[i].Length < 5)
                    {
                        request.Query = busStop[i];
                    }
                    request.Language = "zh-TW";
                    request.Sensor   = false;
                    PlacesResponse response = new PlacesService().GetResponse(request);

                    PlacesResult[] result = response.Results;

                    if (result.Length == 0)
                    {
                        TextSearchRequest stopRequest = new TextSearchRequest();
                        stopRequest.Query    = busStop[i];
                        stopRequest.Language = "zh-TW";
                        stopRequest.Sensor   = false;
                        PlacesResponse stopResponse = new PlacesService().GetResponse(stopRequest);
                        result = stopResponse.Results;
                    }

                    if (reg.IsMatch(result[0].FormattedAddress))
                    {
                        Match match = reg.Match(result[0].FormattedAddress);
                        b = match.Groups["block"].Value + "區";
                    }

                    form.UpdateLog(i + " [ " + busStop[i] + " ] : " + b);
                    output.WriteLine((i + 1) + "," + b + "," + busStop[i]);
                }
                output.Flush();
                output.Close();
                input.Close();
                form.UpdateText("All records finished");
                form.UpdateLog("All records finished");
            }
            catch (Exception e)
            {
                form.UpdateLog("Occur error " + e.Message + ", Stop task");
            }
        }
Beispiel #30
0
        private async void ShowRouteToNearestAddress(string query)
        {
            CheckInternetConnection();

            if (!string.IsNullOrWhiteSpace(query))
            {
                ProgressDialog pleaseWaitDialog = new ProgressDialog(this);
                pleaseWaitDialog.SetMessage(GetString(Resource.String.please_wait));
                pleaseWaitDialog.SetCancelable(false);
                pleaseWaitDialog.Show();

                try
                {
                    MapFragment mapFragment = FragmentManager.FindFragmentByTag <MapFragment>("MAP_FRAGMENT");

                    if (mapFragment.MyLocation == null)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.my_location_unavaliable),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    List <Place> places = await PlacesService.GetPlacesByQuery(query, mapFragment.MyLocation);

                    if (places.Count == 0)
                    {
                        AWidget.Toast.MakeText(this, GetString(Resource.String.no_places_found),
                                               AWidget.ToastLength.Short).Show();
                        return;
                    }

                    nearestPlace = null;
                    Route shortestRoute = null;
                    foreach (var place in places)
                    {
                        var route = await DirectionsService.GetShortestRoute(
                            mapFragment.MyLocation, place.geometry.location);

                        if (shortestRoute == null)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                        else if (route.legs[0].distance.value < shortestRoute.legs[0].distance.value)
                        {
                            nearestPlace  = place;
                            shortestRoute = route;
                        }
                    }

                    mapFragment.DrawRouteToPlace(shortestRoute, nearestPlace);
                    OnPrepareOptionsMenu(actionBarMenu);
                    actionBarMenu.FindItem(Resource.Id.action_add_to_fav).SetVisible(true);
                }
                catch (ApiCallException)
                {
                }
                catch (NearbyPlacesSearchException)
                {
                }
                catch (DirectionsException)
                {
                }
                finally
                {
                    pleaseWaitDialog.Cancel();
                }
            }
        }
        public override IRow Operate(IRow row)
        {
            var request = new TextSearchRequest {
                Query = row[_input].ToString()
            };

            try {
                var response = new PlacesService().GetResponse(request);

                switch (response.Status)
                {
                case ServiceResponseStatus.Ok:
                    var first = response.Results.First();

                    foreach (var field in _output)
                    {
                        switch (field.Name.ToLower())
                        {
                        case "rating":
                            row[field] = first.Rating;
                            break;

                        case "name":
                            row[field] = first.Name;
                            break;

                        case "type":
                        case "locationtype":
                            row[field] = first.Geometry.LocationType.ToString();
                            break;

                        case "icon":
                            row[field] = first.Icon;
                            break;

                        case "place":
                        case "placeid":
                            row[field] = first.PlaceId;
                            break;

                        case "lat":
                        case "latitude":
                            row[field] = first.Geometry.Location.Latitude;
                            break;

                        case "lon":
                        case "long":
                        case "longitude":
                            row[field] = first.Geometry.Location.Longitude;
                            break;

                        case "address":
                        case "formattedaddress":
                            if (field.Equals(_input))
                            {
                                break;
                            }
                            row[field] = first.FormattedAddress;
                            Context.Debug(() => first.FormattedAddress);
                            break;
                        }
                    }
                    break;

                default:
                    Context.Error("Error from Google MAPS API: " + response.Status);
                    break;
                }
            } catch (Exception ex) {
                Context.Error(ex.Message);
            }

            return(row);
        }
 public PlacesController(PlacesService service)
 {
     this.service = service;
 }