예제 #1
0
        public async Task TestGeocodeAddressZeroResults()
        {
            var client = new GeocodeClient();
            var result = await client.GeocodeAddress("nonexistent");

            Assert.AreEqual(GeocodeStatus.ZeroResults, result.Status);
        }
예제 #2
0
        public async Task TestGeocodeAddressWithNullAddress()
        {
            var client = new GeocodeClient();
            await client.GeocodeAddress(null);

            Assert.Fail();
        }
        public MainPage()
        {
            InitializeComponent();
            Search.Clicked += (sender, args) =>
            {
                GeocodeClient client = new GeocodeClient("https://maps.googleapis.com/maps/api/", "AIzaSyBepGH1lMmdhpQ9CIpq6ip6dep3ACzdFMs", "BR");

                var result = client.GetLocationByAddress(new GeocodeRequestInfo()
                {
                    CityName = this.CityName.Text, PlaceNumber = int.Parse(this.LocationNumber.Text), PublicPlaceName = this.PublicPlaceName.Text
                });
                if (result.Status == GeocodeResult.StatusTypes.OK)
                {
                    Result.IsEnabled = true;

                    var mainResult = result.Results.FirstOrDefault();
                    Result.Text = mainResult.FormattedAddress;

                    var viewMapButton = new Button();
                    viewMapButton.Text     = "View on Map";
                    viewMapButton.Clicked += (viewMapSender, viewMapArgs) =>
                    {
                        Navigation.PushAsync(new MapsPagexaml(mainResult.Geometry.Location));
                    };

                    ResultsPanel.Children.Add(viewMapButton);

                    foreach (var addressComponent in mainResult.AddressComponents)
                    {
                        Label addressNameLabel = new Label();
                        addressNameLabel.Text = addressComponent.LongName;

                        var typesString = "(";
                        var types       = addressComponent.Types.ToList();
                        for (int i = 0; i < types.Count; i++)
                        {
                            typesString += types[i];
                            if (i < types.Count - 1)
                            {
                                typesString += " ";
                            }
                        }
                        typesString += ")";
                        Label addressTypesLabel = new Label();
                        addressTypesLabel.Text = typesString;

                        StackLayout stack = new StackLayout();
                        stack.Orientation = StackOrientation.Horizontal;
                        stack.Children.Add(addressNameLabel);
                        stack.Children.Add(addressTypesLabel);

                        ResultsPanel.Children.Add(stack);
                    }
                }
            };
        }
예제 #4
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");
        }
예제 #5
0
        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);
        }
예제 #6
0
        [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);
        }
예제 #7
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);
        }
예제 #8
0
        public async Task <IActionResult> Get(string keyword)
        {
            var geocode = await GeocodeClient.GetGeocodeAsync(HttpUtility.UrlDecode(keyword));

            var entity = await GourmetClient.SearchAsync(geocode.results[0].geometry.location.lng, geocode.results[0].geometry.location.lat);

            var result = _mapper.Map <List <Gourmet> >(entity);

            if (result == null || result.Count == 0)
            {
                return(NotFound());
            }
            return(Ok(result));
        }
예제 #9
0
        public async Task DoRouting()
        {
            var address  = "Routing address here";
            var client   = new GeocodeClient();
            var response = await client.GeocodeAddress(address);

            if (response.Status == GeocodeStatus.Ok)
            {
                var firstResult = response.Results.First();
                var location    = firstResult.Geometry.Location;
                var lat         = location.Latitude;
                var lng         = location.Longitude;
                Console.Write($"{lat} ${lng}");
            }
        }
예제 #10
0
        static void Main(string[] args)
        {
            //The GeocodeClient can convert from an address to GeoCoordinates
            GeocodeClient client = new GeocodeClient(apikey);

            Console.WriteLine("Enter an Address");
            string address = Console.ReadLine();

            //Object that holds our Coordinates
            MapLocation location = client.GetMapLocation(address);

            Console.WriteLine("Latitude: " + location.latitude);
            Console.WriteLine("Longitude: " + location.longitude);
            Console.ReadKey();
        }
예제 #11
0
        public async Task TestGeocodeReverseGeocodingWithResultType()
        {
            var apiKey = "[ADD-API-KEY-HERE]";
            var client = new GeocodeClient(apiKey);

            var resultTypeFilter = new ResultTypeFilter
            {
                Airport = true
            };

            var reverseGeocodingResponse = await client.GeocodeAddress(33.217555, -117.352647, resultTypeFilter : resultTypeFilter);

            var result = reverseGeocodingResponse.Results.First();

            Assert.Equal("KOKB CTAF 122.725, Oceanside, CA 92058, USA", result.FormattedAddress);
        }
        public async Task <GeocodeResult> Geocode(string address)
        {
            var client = new GeocodeClient("AIzaSyCG_-wLmFPaMl2ld7Oh36I82OatdHHZsTQ");

            var response = await client.GeocodeAddress(address);

            if (response.Status == GeocodeStatus.Ok)
            {
                var firstResult = response.Results.First();
                return(firstResult);
            }
            else
            {
                throw new Exception(response.StatusText);
            }
        }
예제 #13
0
        public async Task TestGeocodeReverseGeocodingWithLocationTypeFilter()
        {
            var apiKey = "[ADD-API-KEY-HERE]";
            var client = new GeocodeClient(apiKey);

            var locationTypeFilter = new LocationTypeFilter()
            {
                Rooftop = true
            };

            var reverseGeocodingResponse = await client.GeocodeAddress(33.217555, -117.352647, locationTypeFilter : locationTypeFilter);

            var result = reverseGeocodingResponse.Results.First();

            Assert.Equal("480 Airport Rd, Oceanside, CA 92058, USA", result.FormattedAddress);
        }
예제 #14
0
        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"));
        }
예제 #15
0
        public async Task <List <CoordinateInfo> > FindCoordinates(string locationName)
        {
            var locationResults = new List <CoordinateInfo>();

            var client = new GeocodeClient(new OldGoogleForwarderProxy(), "");

            // we only want US addresses
            var countryFilter = new ComponentFilter()
            {
                Country = "US"
            };

            try
            {
                // Let Google figure out the geocoded address
                var geocodedResults = await client.GeocodeAddress(locationName, null, countryFilter);

                // Only do something if Google says we're OK
                if (geocodedResults.Status == GeocodeStatus.Ok)
                {
                    // Make sure the results are based on a city name
                    var allCityResults = geocodedResults.Results.Where(gr => gr.PartialMatch == false && gr.Types.Any(t => t.Equals("locality")));

                    // Build up the locationResults list
                    foreach (var city in allCityResults)
                    {
                        // Grab the lat & long
                        var coordInfo = new CoordinateInfo()
                        {
                            Latitude = city.Geometry.Location.Latitude, Longitude = city.Geometry.Location.Longitude
                        };

                        // Grab the city & state name out from the address component of the results
                        coordInfo.CityName = city.AddressComponents.First(ac => ac.Types.Any(t => t.Equals("locality"))).ShortName;
                        coordInfo.State    = city.AddressComponents.First(ac => ac.Types.Any(t => t.Equals("administrative_area_level_1"))).ShortName;

                        locationResults.Add(coordInfo);
                    }
                }
            } catch (Exception ex)
            {
                var s = ex.ToString();
            }

            return(locationResults);
        }
예제 #16
0
        public async Task <WeatherLocation> FindLocationCoordinatesAsync(string locationName)
        {
            var gc         = new GeocodeClient();
            var gcResponse = await gc.GeocodeAddress(locationName);

            var gcResult = gcResponse.Results.FirstOrDefault();

            if (gcResult == null)
            {
                return(null);
            }

            return(new WeatherLocation()
            {
                Latitude = gcResult.Geometry.Location.Latitude,
                Longitude = gcResult.Geometry.Location.Longitude,
                LocationName = locationName
            });
        }
예제 #17
0
        public static async Task <GetGeoCodeResponse> GetGeoCode(string address)
        {
            GetGeoCodeResponse response = new GetGeoCodeResponse();
            var client = new GeocodeClient("AIzaSyDbfVH8TAC_3Itet0g5PIu1iJ7OY7ebr8Y");

            var resp = await client.GeocodeAddress(address);

            if (resp.Status == GeocodeStatus.Ok)
            {
                var firstResult = resp.Results.First();
                var location    = firstResult.Geometry.Location;
                var lat         = location.Latitude;
                var lng         = location.Longitude;

                response.Lat  = lat.ToString();
                response.Long = lng.ToString();

                return(response);
            }

            return(null);
        }
 public GeocodeClientAdapter(IEnv env, IMetricService metrics, ILogger <IGeocodeClientAdapter> logger)
 {
     _metrics = metrics;
     _client  = new GeocodeClient(env.GoogleApiKey);
     _logger  = logger;
 }
예제 #19
0
 protected void Page_Load(object sender, EventArgs e)
 {
     addresses     = new List <MapLocation>();
     geocodeClient = new GeocodeClient("AIzaSyC3hfMFJNWo9f7k0_8rbdV3r-ic4bfLExs");
 }
예제 #20
0
 private void Form1_Load(object sender, EventArgs e)
 {
     addresses = new List <MapLocation>();
     //PUT YOUR GOOGLE MAPS API KEY HERE
     geocodeClient = new GeocodeClient("AIzaSyC3hfMFJNWo9f7k0_8rbdV3r-ic4bfLExs");
 }
예제 #21
0
 public GeocodeClientTestFixture()
 {
     Client = new GeocodeClient();
 }
예제 #22
0
 protected void Page_Load(object sender, EventArgs e)
 {
     addresses     = new List <MapLocation>();
     geocodeClient = new GeocodeClient();
 }