Provides a direct way to access a geocoder via an HTTP request. Additionally, the service allows you to perform the converse operation (turning coordinates into addresses); this process is known as "reverse geocoding."
        public void GeocodeResult_Has_BoundsProperty()
        {
            var request = new GeocodingRequest
            {
                Address = "Boston",
                Sensor = false
            };

            var response = new GeocodingService().GetResponse(request);

            Assert.IsNotNull(response.Results[0].Geometry.Bounds);
            Assert.IsNotNull(response.Results[0].Geometry.Bounds.Southwest);
            Assert.IsNotNull(response.Results[0].Geometry.Bounds.Northeast);
        }
        public void Geocode_With_AddressComponent_Locking()
        {
            var requestGB = new GeocodingRequest
            {
                Address    = "Boston",
                Components = "country:GB"
            };

            var requestUS = new GeocodingRequest
            {
                Address    = "Boston",
                Components = "country:US"
            };

            var responseGB = new GeocodingService().GetResponse(requestGB);
            var responseUS = new GeocodingService().GetResponse(requestUS);

            Assert.AreEqual(ServiceResponseStatus.Ok, responseGB.Status);
            Assert.AreEqual(ServiceResponseStatus.Ok, responseUS.Status);

            foreach (var r in responseGB.Results)
            {
                Assert.IsTrue(r.FormattedAddress.EndsWith("UK"), r.FormattedAddress + " <- Should be in UK");
            }

            foreach (var r in responseUS.Results)
            {
                Assert.IsTrue(r.FormattedAddress.EndsWith("USA"), r.FormattedAddress + " <- Should be in USA");
            }
        }
        public Coordenadas BuscarCoordenas(Endereco endereco)
        {
            var gmapsRequest = new GeocodingRequest();

            gmapsRequest.Address = string.Format("{0}, {1}, {2} - {3}, {4}, {5}",
                    endereco.Logradouro,
                    endereco.Numero,
                    endereco.Bairro,
                    endereco.Cidade,
                    endereco.Estado,
                    endereco.Cep);
            gmapsRequest.Sensor = false;
            gmapsRequest.Language = "pt";

            var gmapsResponse = new GeocodingService().GetResponse(gmapsRequest);

            if (gmapsResponse.Status != ServiceResponseStatus.Ok)
                throw new Exception();

            return new Coordenadas()
            {
                Latitude = gmapsResponse.Results.First().Geometry.Location.Latitude,
                Longitude = gmapsResponse.Results.First().Geometry.Location.Longitude
            };
        }
		public void Geocode_With_AddressComponent_Locking()
		{
			var requestGB = new GeocodingRequest
			{
				Address = "Boston",
				Sensor = false,
				Components = "country:GB"
			};

			var requestUS = new GeocodingRequest
			{
				Address = "Boston",
				Sensor = false,
				Components = "country:US"
			};

			var responseGB = new GeocodingService().GetResponse(requestGB);
			var responseUS = new GeocodingService().GetResponse(requestUS);

			Assert.AreEqual(ServiceResponseStatus.Ok, responseGB.Status);
			Assert.AreEqual(ServiceResponseStatus.Ok, responseUS.Status);

			foreach (var r in responseGB.Results)
			{
				Assert.IsTrue(r.FormattedAddress.EndsWith("UK"), r.FormattedAddress + " <- Should be in UK");
			}

			foreach (var r in responseUS.Results)
			{
				Assert.IsTrue(r.FormattedAddress.EndsWith("USA"), r.FormattedAddress + " <- Should be in USA");
			}
		}
        public void GetGeocodingForAddress1()
        {
            // Arrange
            var request = new GeocodingRequest {
                Address = "1600 Amphitheatre Parkway Mountain View CA"
            };

            // Act
            var response = new GeocodingService().GetResponse(request);

            // Assert
            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
            Assert.AreEqual(1, response.Results.Length);

            var result = response.Results.Single();

            Assert.AreEqual("Google Bldg 42, 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA", result.FormattedAddress);
            Assert.AreEqual(LocationType.Rooftop, result.Geometry.LocationType);

            var expectedLocation = new LatLng(37.42219410, -122.08459320);

            Assert.That(expectedLocation, Is.EqualTo(result.Geometry.Location).Using(LatLngComparer.Within(0.00001f)));

            Viewport expectedViewport = new Viewport(
                southWest: new LatLng(37.42084511970850, -122.0859421802915),
                northEast: new LatLng(37.42354308029149, -122.0832442197085)
                );

            Assert.That(expectedViewport.Southwest, Is.EqualTo(result.Geometry.Viewport.Southwest).Using(LatLngComparer.Within(0.00001f)));
            Assert.That(expectedViewport.Northeast, Is.EqualTo(result.Geometry.Viewport.Northeast).Using(LatLngComparer.Within(0.00001f)));
        }
 public void Empty_address()
 {
     Assert.Throws <HttpRequestException>(() =>
     {
         var request = new GeocodingRequest {
             Address = ""
         };
         var response = new GeocodingService().GetResponse(request);
     });
 }
示例#7
0
 protected void btnFindBillingAddress_Click(object sender, EventArgs e)
 {
     // Find address
     var request = new GeocodingRequest();
     request.Address = txtBillingPostcode.Text;
     // not sure what this is but it needs to be false
     request.Sensor = false;
     var response = new GeocodingService().GetResponse(request);
     var result = response.Results.First();
     lblBillingAddress.Text = "Billing Address: " + "<br/><br/>" + txtBillingHouseNum.Text + " " + result.AddressComponents.ElementAt(1).LongName + "<br/>" + result.AddressComponents.ElementAt(2).LongName + "<br/>" + result.AddressComponents.ElementAt(3).LongName + "<br/>" + result.AddressComponents.ElementAt(4).LongName + "<br/>" + result.AddressComponents.ElementAt(0).LongName + "<br/>" + result.AddressComponents.ElementAt(5).ShortName;
 }
示例#8
0
        public void hello(double latitude, double longitude)
        {
            var resource = ResourceReader.GetResourceAsync("Foodies.Query.Google.client_secret.json");
            var jsonSerializer = new DataContractJsonSerializer(typeof (GoogleClientSecret));
            var web = (Web) jsonSerializer.ReadObject(GenerateStreamFromString(resource.Result));

            GoogleSigned.AssignAllServices(new GoogleSigned("710337540398-daee4j6uu41s6muqoetgaj6krro8jojj.apps.googleusercontent.com", "sdNdpWuiqwRVtPpThsguVGFp"));
            var request = new GeocodingRequest { Address = new Location("latLng," + latitude + longitude), Sensor = false, };
            var geocodingService = new GeocodingService();
            var response = geocodingService.GetResponse(request);
        }
		private void searchButton_Click(object sender, RoutedEventArgs e)
		{
			var request = new GeocodingRequest();
			request.Address = searchTextBox.Text;
			request.Sensor = false;
			var response = new GeocodingService().GetResponse(request);

			if (response.Status == ServiceResponseStatus.Ok)
			{
				resultsTreeView.ItemsSource = response.Results.ToTree();
			}
		}
        public void Signed_GeocodingRequest_Works()
        {
            var request = new GeocodingRequest
            {
                Address = "Stathern, UK",
                Sensor = false
            };

            GoogleSigned.AssignAllServices(GetRealSigningInstance());
            var response = new GeocodingService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
        }
示例#11
0
        public void Utf8_Request_And_Response()
        {
            var request = new GeocodingRequest
            {
                Address = "AL. GRUNWALDZKA 141, Gdańsk, 80 - 264, POLAND"
            };

            var response = new GeocodingService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
            Assert.AreEqual(LocationType.Rooftop, response.Results[0].Geometry.LocationType);
            Assert.AreEqual("Gdańsk", response.Results[0].AddressComponents[3].LongName);
        }
        public void Geocode_Without_AddressComponent_Locking()
        {
            var request = new GeocodingRequest
            {
                Address = "Boston"
            };

            var response = new GeocodingService().GetResponse(request);

            foreach (var r in response.Results)
            {
                Assert.IsTrue(r.FormattedAddress.EndsWith("USA"));
            }
        }
        public void GeocodeResult_Has_BoundsProperty()
        {
            var request = new GeocodingRequest
            {
                Address = "Boston"
            };

            var response = new GeocodingService().GetResponse(request);

            Assert.AreEqual(ServiceResponseStatus.Ok, response.Status);
            Assert.IsNotNull(response.Results[0].Geometry.Bounds);
            Assert.IsNotNull(response.Results[0].Geometry.Bounds.Southwest);
            Assert.IsNotNull(response.Results[0].Geometry.Bounds.Northeast);
        }
        public void Geocode_Without_AddressComponent_Locking()
        {
            var request = new GeocodingRequest
            {
                Address = "Boston",
                Sensor = false
            };

            var response = new GeocodingService().GetResponse(request);

            foreach (var r in response.Results)
            {
                Assert.IsTrue(r.FormattedAddress.EndsWith("USA"));
            }
        }
        public void Empty_address()
        {
            // expectations
            var expectedStatus = ServiceResponseStatus.ZeroResults;
            var expectedResultCount = 0;

            // test
            var request = new GeocodingRequest();
            request.Sensor = false;
            request.Address = "";
            var response = new GeocodingService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status);
            Assert.AreEqual(expectedResultCount, response.Results.Count());
        }
        public void GeocodeResult_Supports_PostalTownAndPostalCodePrefix()
        {
            var request = new GeocodingRequest
            {
                Address = "Stathern, UK",
                Sensor = false
            };

            var response = new GeocodingService().GetResponse(request);

            var postalTown = response.Results[0].AddressComponents.First(x => x.ShortName == "Melton Mowbray");
            Assert.IsFalse(postalTown.Types.Contains(AddressType.Unknown), postalTown.ShortName + " should be AddressType PostalTown");

            var postalCodePrefix = response.Results[0].AddressComponents.First(x => x.ShortName == "LE14");
            Assert.IsFalse(postalCodePrefix.Types.Contains(AddressType.Unknown), postalCodePrefix.ShortName + " should be AddressType PostalCodePrefix");
        }
示例#17
0
        public Location(string Address, string tag="")
        {
            Address=Address.Trim();
            if (string.IsNullOrEmpty(Address))
            {
                xValue = double.MaxValue;
                yValue = double.MaxValue;
                TaggedAddress = "";
                TaggedDescription = "";
            }

            else
            {
                try
                {
                    var request = new GeocodingRequest();
                    request.Address = Address;
                    request.Sensor = false;
                    var response = new GeocodingService().GetResponse(request);
                    var result = response.Results.First();
                    if (tag == "")
                    { TaggedDescription = Address; }
                    else
                    {
                        TaggedDescription = tag;
                    }
                    TaggedAddress = result.FormattedAddress;
                    xValue = Convert.ToDouble(result.Geometry.Location.Latitude);
                    yValue = Convert.ToDouble(result.Geometry.Location.Longitude);
                    //MessageBox.Show("Found Location At: " + result.FormattedAddress + " Latitude: " + xValue + " Longitude: " + yValue);
                }
                catch
                {
                    xValue = double.MaxValue;
                    yValue = double.MaxValue;
                    if (tag == "")
                    {
                        TaggedDescription = Address;
                    }
                    else
                    {
                        TaggedDescription = tag;
                    }
                    TaggedAddress = Address;
                }
            }
        }
        public void GetGeocodingForAddress2()
        {
            // test
            var request = new GeocodingRequest();

            request.Address = "11 Wall Street New York NY 10005";
            var actual = new GeocodingService().GetResponse(request);

            // asserts
            Assert.AreEqual(ServiceResponseStatus.Ok, actual.Status);
            Assert.AreEqual(1, actual.Results.Length);

            var actualResult = actual.Results.Single();

            Assert.AreEqual(new AddressType[] { AddressType.StreetAddress }, actualResult.Types);
            Assert.AreEqual("11 Wall St, New York, NY 10005, USA", actualResult.FormattedAddress);
        }
		public void GeocodingRequest_Example()
		{
			var request = new GeocodingRequest();
			request.Address = "1600 Amphitheatre Parkway";
			request.Sensor = false;
			var response = new GeocodingService().GetResponse(request);

			// --break in the online version here-- //

			var result = response.Results.First();

			Console.WriteLine("Full Address: " + result.FormattedAddress);         // "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA"
			Console.WriteLine("Latitude: " + result.Geometry.Location.Latitude);   // 37.4230180
			Console.WriteLine("Longitude: " + result.Geometry.Location.Longitude); // -122.0818530

			Assert.Pass();
		}
        public void GeocodeResult_Supports_PostalTownAndPostalCodePrefix()
        {
            var request = new GeocodingRequest
            {
                Address = "Stathern, UK"
            };

            var response = new GeocodingService().GetResponse(request);

            var postalTown = response.Results[0].AddressComponents.First(x => x.ShortName == "Melton Mowbray");

            Assert.IsFalse(postalTown.Types.Contains(AddressType.Unknown), postalTown.ShortName + " should be AddressType PostalTown");

            var postalCodePrefix = response.Results[0].AddressComponents.First(x => x.ShortName == "LE14");

            Assert.IsFalse(postalCodePrefix.Types.Contains(AddressType.Unknown), postalCodePrefix.ShortName + " should be AddressType PostalCodePrefix");
        }
        public void GetGeocodingForAddress1()
        {
            // expectations
            var expectedStatus = ServiceResponseStatus.Ok;
            var expectedResultCount = 1;
            var expectedType = AddressType.StreetAddress;
            var expectedFormattedAddress = "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA";
            var expectedComponentTypes = new AddressType[] {
                AddressType.StreetNumber,
                AddressType.Route,
                AddressType.Locality,
                AddressType.AdministrativeAreaLevel1,
                AddressType.AdministrativeAreaLevel2,
                AddressType.AdministrativeAreaLevel3,
                AddressType.Country,
                AddressType.PostalCode,
                AddressType.Political
            };
            var expectedLocation = new LatLng(37.42219410, -122.08459320);
            var expectedLocationType = LocationType.Rooftop;
            Viewport expectedViewport = new Viewport(
                southWest: new LatLng(37.42084511970850, -122.0859421802915),
                northEast: new LatLng(37.42354308029149, -122.0832442197085)
            );

            // test
            var request = new GeocodingRequest();
            request.Address = "1600 Amphitheatre Parkway Mountain View CA";
            request.Sensor = false;
            var response = new GeocodingService().GetResponse(request);

            // asserts
            Assert.AreEqual(expectedStatus, response.Status, "Status");
            Assert.AreEqual(expectedResultCount, response.Results.Length, "ResultCount");
            Assert.AreEqual(expectedType, response.Results.Single().Types.First(), "Type");
            Assert.AreEqual(expectedFormattedAddress, response.Results.Single().FormattedAddress, "FormattedAddress");
            //Assert.IsTrue(
            //    expectedComponentTypes.OrderBy(x => x).SequenceEqual(
            //        response.Results.Single().AddressComponents.SelectMany(y => y.Types).Distinct().OrderBy(z => z)), "Types");
            //Assert.AreEqual(expectedLatitude, response.Results.Single().Geometry.Location.Latitude, "Latitude");
            Assert.That(expectedLocation, Is.EqualTo(response.Results[0].Geometry.Location).Using(LatLngComparer.Within(0.000001f)), "Longitude");
            Assert.AreEqual(expectedLocationType, response.Results.Single().Geometry.LocationType, "LocationType");
            //Assert.AreEqual(expectedSouthwestLatitude, response.Results.Single().Geometry.Viewport.Southwest.Latitude, "Southwest.Latitude");
            //Assert.AreEqual(expectedSouthwestLongitude, response.Results.Single().Geometry.Viewport.Southwest.Longitude, "Southwest.Longitude");
            //Assert.AreEqual(expectedNortheastLatitude, response.Results.Single().Geometry.Viewport.Northeast.Latitude, "Northeast.Latitude");
            //Assert.AreEqual(expectedNortheastLongitude, response.Results.Single().Geometry.Viewport.Northeast.Longitude, "Northeast.Longitude");
        }
        public void GetGeocodingForAddress2()
        {
            // expectations
            GeocodeResponse expected = new GeocodeResponse()
            {
                Status = ServiceResponseStatus.Ok,
                Results = new Result[] {
                    new Result() {

                        AddressComponents = new AddressComponent[] {
                            MakeAddressComponent("11","11",	AddressType.StreetNumber)
                            , MakeAddressComponent("Wall St","Wall Street", AddressType.Route)
                            , MakeAddressComponent("Lower Manhattan", "Lower Manhattan", AddressType.Neighborhood, AddressType.Political)
                            , MakeAddressComponent("Manhattan", "Manhattan", AddressType.Sublocality, AddressType.Political)
                            , MakeAddressComponent("New York", "New York", AddressType.Locality, AddressType.Political)
                            , MakeAddressComponent("New York", "New York", AddressType.AdministrativeAreaLevel2, AddressType.Political)
                            , MakeAddressComponent("NY", "New York", AddressType.AdministrativeAreaLevel1, AddressType.Political)
                            , MakeAddressComponent("US", "United States", AddressType.Country, AddressType.Political)
                        }
                        , FormattedAddress = "11 Wall Street, New York, NY 10005, USA"
                        , Geometry = MakeGeometry(LocationType.Rooftop,
                                40.7068599,-74.0111281 //location
                                , 40.7055109,-74.0124771 //swBound
                                , 40.7082089,-74.0097791) //neBound
                        , Types = new AddressType[] { AddressType.StreetAddress }
                    }
                }
            };

            // test
            var request = new GeocodingRequest();
            request.Address = "11 Wall Street New York NY 10005";
            request.Sensor = false;
            var actual = new GeocodingService().GetResponse(request);

            // asserts
            Assert.AreEqual(expected.Status, actual.Status, "Status");
            Assert.AreEqual(expected.Results.Length, actual.Results.Length, "ResultCount");

            var expectedResult = expected.Results.First(); var actualResult = actual.Results.First();
            Assert.AreEqual(expectedResult.Types, actualResult.Types, "Result.First().Types");
            Assert.AreEqual(expectedResult.FormattedAddress, actualResult.FormattedAddress, "Resut.First().FormattedAddress");

            //Assert.That(expectedResult.AddressComponents, Is.EquivalentTo(actualResult.AddressComponents));

            //Assert.IsTrue(
            //    expectedComponentTypes.OrderBy(x => x).SequenceEqual(
            //        response.Results.Single().AddressComponents.SelectMany(y => y.Types).Distinct().OrderBy(z => z)), "Types");

            //tolerance needed when testing doubles
            //http://stackoverflow.com/questions/4787125/evaluate-if-two-doubles-are-equal-based-on-a-given-precision-not-within-a-certa
            //double tolerance = GetTolerance(expectedResult.Geometry.Viewport.Southwest.Latitude, 7);
            //Assert.That(expectedResult.Geometry.Viewport.Southwest, Is.EqualTo(actualResult.Geometry.Viewport.Southwest).Within(latlngTolerance));
            //Assert.That(expectedResult.Geometry.Viewport.Southwest, Is.EqualTo(actualResult.Geometry.Viewport.Southwest).Within(0.0000001d));

            //Assert.AreEqual(expectedLatitude, response.Results.Single().Geometry.Location.Latitude, "Latitude");
            //Assert.AreEqual(expectedLongitude, response.Results.Single().Geometry.Location.Longitude, "Longitude");
            //Assert.AreEqual(expectedLocationType, response.Results.Single().Geometry.LocationType, "LocationType");
            //Assert.AreEqual(expectedSouthwestLatitude, response.Results.Single().Geometry.Viewport.Southwest.Latitude, "Southwest.Latitude");
            //Assert.AreEqual(expectedSouthwestLongitude, response.Results.Single().Geometry.Viewport.Southwest.Longitude, "Southwest.Longitude");
            //Assert.AreEqual(expectedNortheastLatitude, response.Results.Single().Geometry.Viewport.Northeast.Latitude, "Northeast.Latitude");
            //Assert.AreEqual(expectedNortheastLongitude, response.Results.Single().Geometry.Viewport.Northeast.Longitude, "Northeast.Longitude");
        }
示例#23
0
        GeocodingService CreateService()
        {
            var svc = new GeocodingService(TestingApiKey);

            return(svc);
        }