Exemplo n.º 1
0
    public async Task HandleAsync()
    {
        var message = "Please specify an address";

        if (_args.Count == 0)
        {
            await _botService.SendMessageAsync(message, _chatId);

            return;
        }

        var mapsApi  = new GoogleMapsApi(_clientFactory, _apiKey);
        var response = await mapsApi.InvokeAsync(_args);

        var geometryLocation = response.Results?[0].Geometry?.Location;

        if (response.Status != "OK" || geometryLocation is null)
        {
            message = "Nothing \uD83D\uDE22";
            await _botService.SendMessageAsync(message, _chatId);

            return;
        }

        await _botService.SendLocationAsync(geometryLocation.Lattitude, geometryLocation.Longtitude, _chatId);
    }
        public UserRepositoryTests()
        {
            var connection = new MongoConnection
            {
                ConnectionString = "mongodb://127.0.0.1:27017/edwardjenner",
                Database         = "edwardjenner"
            };

            var googleSettings = new GoogleSettings
            {
                ApiKey = "AIzaSyA24yDHFfDuszVUomPTe8EiLTIdGjbESYc"
            };

            var googleMapsApi = new GoogleMapsApi(googleSettings);

            var redisConnection = new RedisConnection
            {
                Host    = "127.0.0.1",
                Port    = 6379,
                Seconds = 60000
            };

            var cacheGoogleGeocodeService = new CacheService <GoogleGeocodeResult>(redisConnection);

            _userRepository = new UserRepository(connection, googleMapsApi, cacheGoogleGeocodeService);
        }
Exemplo n.º 3
0
    private async Task <Tuple <Status, Location> > GetLocationAsync(IEnumerable <string> place)
    {
        var mapsApi  = new GoogleMapsApi(_clientFactory, _apiKey);
        var response = await mapsApi.InvokeAsync(place);

        var geometryLocation = response.Results?[0].Geometry?.Location;

        if (response.Status != "OK" || geometryLocation is null)
        {
            return(new Tuple <Status, Location>(Status.Error, new Location()));
        }

        return(new Tuple <Status, Location>(Status.Ok, geometryLocation));
    }
        public void GetStaticMapGeneralTest()
        {
            var parameters = new MapParameters
            {
                Center = "Odessa",
                Format = MapFormat.JPEG,
                Type   = MapType.Roadmap,
                Zoom   = "14"
            };

            var googleMapApi = new GoogleMapsApi("AIzaSyAc8NoMPpWFiILAS5HQ3jMjFoFVAJN9Ma4", parameters);
            var response     = googleMapApi.GetStaticMapImage().Result;

            Assert.IsNotNull(response);
        }
Exemplo n.º 5
0
        static int GoogleMapsDirectionCross(ConsoleService c, string cmdName, string str)
        {
            ConsoleParam[] args =
            {
                new ConsoleParam("[dir]", ConsoleService.Prompt, "Directory path: ", ConsoleService.EvalNotEmpty, null),
            };

            ConsoleParamValueList vl = c.ParseCommandList(cmdName, str, args);

            string dir = vl.DefaultParam.StrValue;

            string apiKey = Lfs.ReadStringFromFile(dir._CombinePath("ApiKey.txt"), oneLine: true);

            string srcListText  = Lfs.ReadStringFromFile(dir._CombinePath("Source.txt"));
            string destListText = Lfs.ReadStringFromFile(dir._CombinePath("Destination.txt"));

            string[] srcList  = srcListText._GetLines(removeEmpty: true);
            string[] destList = destListText._GetLines(removeEmpty: true);

            using var googleMapsApi = new GoogleMapsApi(new GoogleMapsApiSettings(apiKey: apiKey));

            DateTimeOffset departure = Util.GetStartOfDay(DateTime.Now.AddDays(2))._AsDateTimeOffset(isLocalTime: true);

            List <DirectionCrossResults> csv = new List <DirectionCrossResults>();

            foreach (string src in srcList)
            {
                foreach (string dest in destList)
                {
                    Console.WriteLine($"「{src}」 → 「{dest}」 ...");

                    DirectionCrossResults r = new DirectionCrossResults();

                    r.Start = src;
                    r.End   = dest;

                    try
                    {
                        var result = googleMapsApi.CalcDurationAsync(src, dest, departure)._GetResult();

                        if (result.IsError == false)
                        {
                            r.StartAddress = result.StartAddress;
                            r.EndAddress   = result.EndAddress;
                            r.Error        = "";
                            r.Duration     = result.Duration;
                            r.DistanceKm   = result.DistanceKm;
                            r.RouteSummary = result.RouteSummary;

                            $"  {r.Duration} - {r.DistanceKm} km ({r.RouteSummary})"._Print();
                        }
                        else
                        {
                            r.Error = result.ErrorString;
                            r.Error._Print();
                        }
                    }
                    catch (Exception ex)
                    {
                        ex._Debug();
                        r.Error = ex.Message;
                    }

                    csv.Add(r);
                }
            }

            string csvText = csv._ObjectArrayToCsv(withHeader: true);

            Lfs.WriteStringToFile(dir._CombinePath("Result.csv"), csvText, writeBom: true);

            return(0);
        }