示例#1
0
        static async Task Main(string[] args)
        {
            string sampleAddress = "<address>";

            string googleKey = "<insert_key>";
            string bingKey   = "<insert_key>";

            var gcClient = new HttpClient(new GeoCoding.Utils.Http.GeoHandler(3));

            var geoServices = new List <IGeoService>();

            geoServices.Add(GeoServiceFactory.CreateBingService(gcClient, bingKey));
            geoServices.Add(GeoServiceFactory.CreateGoogleService(gcClient, googleKey));


            try
            {
                var translator = new AddressTranslator(geoServices);

                var allResult = await translator.GetAllCoordinates(sampleAddress, GeoCoding.Data.AccuracyLevel.Lowest);

                Console.WriteLine($"GetCoordinate(All) - Address: {sampleAddress}: Coordinates:\n{JsonConvert.SerializeObject(allResult, Formatting.Indented)}");

                var singleResult = await translator.GetCoordinate(sampleAddress, GeoCoding.Data.AccuracyLevel.Lowest);

                Console.WriteLine($"GetCoordinate(first) - Address: {sampleAddress}: Coordinates:\n{JsonConvert.SerializeObject(singleResult, Formatting.Indented)}");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
        public async Task BothActiveServicesBingPrioritizedAccuracyInvalidChecks(AccuracyLevel bingAccuracy, AccuracyLevel googleAccuracy,
                                                                                 AccuracyLevel threshold)
        {
            var geoServices = new List <IGeoService>();

            var googleServiceMock = new Mock <IGeoService>();

            googleServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = googleAccuracy, Service = ServiceType.Google
            });

            var bingServiceMock = new Mock <IGeoService>();

            bingServiceMock.Setup(x => x.GetCoordinate("Good address")).ReturnsAsync(new GeoCoordinate {
                Accuracy = bingAccuracy, Service = ServiceType.Bing
            });

            geoServices.Add(googleServiceMock.Object);
            geoServices.Add(bingServiceMock.Object);

            var translator = new AddressTranslator(geoServices);

            var coordinates = await translator.GetCoordinate("Good address", threshold);

            Assert.Null(coordinates);
        }