Esempio n. 1
0
 public async Task TestComponentFilter()
 {
     var client = new GeocodeClient();
     var result = await client.GeocodeAddress("santa cruz");
     Assert.IsTrue(result.Results.Count() > 1, "'santa cruz' should return multiple results when used without component filter.");
     result = await client.GeocodeAddress("santa cruz", null, new ComponentFilter { Country = "es" });
     Assert.IsTrue(result.Results.Count() == 1, "'santa cruz' should return singler result when used with Country=es filter");
 }
 public async Task TestGeocodeAddressWithPartialMatch()
 {
     const string address = "21 Henr St, Bristol, UK";
     var client = new GeocodeClient();
     var result = await client.GeocodeAddress(address);
     Assert.AreEqual(GeocodeStatus.Ok, result.Status);
     Assert.AreEqual(true, result.Results.All(r => r.PartialMatch));
     Assert.AreEqual(true, result.Results.Length > 0);
 }
        public async Task TestGeocodeAddressWithRegion()
        {
            var client = new GeocodeClient();
            var result = await client.GeocodeAddress("London", region: "ca");
            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.AreEqual("London, ON, Canada", result.Results.First().FormattedAddress);

            result = await client.GeocodeAddress("London", region: "uk");
            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.AreEqual("London, UK", result.Results.First().FormattedAddress);
        }
 [Ignore]  // Unignore after adding client credentials.
 public async Task TestGeocodeAddressWithPartialMatchWithApiForWork()
 {
     var clientId = "[ADD-CLIENT-ID-HERE]";
     var cryptoKey = "[ADD-CRYPTO_KEY_HERE]";;
     const string address = "21 Henr St, Bristol, UK";
     var client = new GeocodeClient(clientId, cryptoKey);
     var result = await client.GeocodeAddress(address);
     Assert.AreEqual(GeocodeStatus.Ok, result.Status);
     Assert.AreEqual(true, result.Results.All(r => r.PartialMatch));
     Assert.AreEqual(true, result.Results.Length > 0);
 }
Esempio n. 5
0
        public async Task TestGeocodeAddressWithRegionViaGeocodeRequest()
        {
            var client = new GeocodeClient(settings.GeocodeAPIKey);
            var result = await client.GeocodeRequest(new GeocodeRequest { address = "London", region = "ca" });
            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.AreEqual("London, ON, Canada", result.Results.First().FormattedAddress);

            result = await client.GeocodeRequest(new GeocodeRequest { address = "London", region = "uk" });
            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.AreEqual("London, UK", result.Results.First().FormattedAddress);
        }
 public async Task TestTestGeocodeAddressWithExactMatch()
 {
     const string address = "21 Henrietta St, Bristol, UK";
     var client = new GeocodeClient();
     var response = await client.GeocodeAddress(address);
     Assert.AreEqual(GeocodeStatus.Ok, response.Status);
     Assert.AreEqual(false, response.Results.All(r => r.PartialMatch));
     Assert.AreEqual(true, response.Results.Length == 1);
     var result = response.Results[0];
     Assert.AreEqual("21 Henrietta Street, Bristol, City of Bristol BS5 6HU, UK", result.FormattedAddress);
     Assert.AreEqual(51, (int)result.Geometry.Location.Latitude);
     Assert.AreEqual(-2, (int)result.Geometry.Location.Longitude);
     Assert.IsTrue(result.Types.Contains("street_address"));
 }
Esempio n. 7
0
		public async Task Geocode()
		{
			try
			{
				var geocoder = new GeocodeClient();
				var longAddr = string.Format("{0} {1} {2}, {3} {4} {5}", AddrLine1, AddrLine2, City, State, PostalCode, Country);
				var response = await geocoder.GeocodeAddress(longAddr);

				var result = response.Results.First();

				Latitude = Convert.ToDecimal(result.Geometry.Location.Latitude);
				Longitude = Convert.ToDecimal(result.Geometry.Location.Longitude);
			}
			catch (Exception)
			{
				// geocoding failed
			}
		}
 public async Task TestGeocodeAddressWithNullAddress()
 {
     var client = new GeocodeClient();
     await client.GeocodeAddress(null);
     Assert.Fail();
 }
 public async Task TestGeocodeAddressZeroResults()
 {
     var client = new GeocodeClient();
     var result = await client.GeocodeAddress("nonexistent");
     Assert.AreEqual(GeocodeStatus.ZeroResults, result.Status);
 }
Esempio n. 10
0
 public async Task TestGeocodeAddressWithRegionBoundsComponentsAndLanguageViaGeocodeRequest()
 {
     var client = new GeocodeClient(settings.GeocodeAPIKey);
     var result = await client.GeocodeRequest(new GeocodeRequest { 
         address = "London", 
         region = "ca",
         bounds = new GeoViewport{ 
             Northeast = new GeoCoordinate{Latitude = -51.5073509m, Longitude = -0.1277583m }, 
             Southwest = new GeoCoordinate{Latitude = 51.5073509m, Longitude = 0.1277583m } },
         components = GeocodeComponent.locality, 
         language = "en-GB"
     });
     Assert.AreEqual(GeocodeStatus.Ok, result.Status);
     Assert.AreEqual("London, ON, Canada", result.Results.First().FormattedAddress);
 }
Esempio n. 11
0
        public async Task TestReverseGeocodeWithLocationResultTypeLanguageResultViaGeocodeReverseRequest()
        {
            if (string.IsNullOrEmpty(settings.GeocodeAPIKey))
            {
                Assert.Inconclusive("APIKey was not provided");
                return;
            }


            var client = new GeocodeClient(settings.GeocodeAPIKey);
            var result = await client.GeocodeRequest(
                new GeocodeReverseRequest
                {
                    latlng = new GeoCoordinate { Latitude = 51.5073509m, Longitude = -0.1277583m },
                    language = "en-GB",
                    location_type = LocationType.Approximate,
                    result_type = GeocodeComponent.locality
                });

            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.IsTrue(result.Results.Any(i => i.FormattedAddress == "London, UK"));
        }
Esempio n. 12
0
        public async Task TestReverseGeocodeWithLanguageResultViaGeocodeReverseRequest()
        {
            var client = new GeocodeClient(settings.GeocodeAPIKey);
            var result = await client.GeocodeRequest(
                new GeocodeReverseRequest { 
                    latlng = new GeoCoordinate { Latitude = 51.5073509m, Longitude = -0.1277583m },
                    language = "en-GB", 
                });

            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.IsTrue(result.Results.Any(i => i.FormattedAddress == "3 Whitehall, London SW1A 2DD, UK"));
        }
Esempio n. 13
0
        public async Task TestReversePlaceId()
        {
            if (string.IsNullOrEmpty(settings.GeocodeAPIKey))
            {
                Assert.Inconclusive("APIKey was not provided");
                return;
            }
            var client = new GeocodeClient(settings.GeocodeAPIKey);
            var result = await client.GeocodeReverse("ChIJb9KHxsgEdkgRe82UfSxQIv0");

            Assert.AreEqual(GeocodeStatus.Ok, result.Status);
            Assert.IsTrue(result.Results.Any(i => i.FormattedAddress == "London WC2N, UK"));

        }
Esempio n. 14
0
 public async Task TestGeocodeAddressZeroResults()
 {
     var client = new GeocodeClient(settings.GeocodeAPIKey);
     var result = await client.GeocodeAddress("");
     Assert.Fail();
 }