Esempio n. 1
0
        public Search(string postcode)
        {
            Location        origin      = new Location(postcode);
            BoundingBox     boundingBox = GetBoundingBox(origin, 10);
            List <Location> locations   = GetEnvironmentVarables.GenerateLocations();

            locations.ForEach(x => Console.WriteLine(x.ToString() + ", Distance: [" + Distance(origin, x) + "]"));

            //locations = locations.Where(x =>
            //	x.Latitude < boundingBox.MaxLatitude &&
            //	x.Latitude > boundingBox.MinLatitude &&
            //	x.Longitude < boundingBox.MaxLongitude &&
            //	x.Longitude > boundingBox.MinLongitude)
            //	.ToList();
        }
Esempio n. 2
0
        private void SetCoordinatesFromPostcode(string postcode)
        {
            if (!IsValidPostcode(postcode))
            {
                throw new ArgumentException($"The postcode [{postcode}] was invalid.");
            }

            string  uri            = "https://maps.googleapis.com/maps/api/geocode/json?components=postal_code:" + postcode + "&key=" + GetEnvironmentVarables.GetGoogleApiKey();
            string  responceString = Web.Get(uri);
            JObject responseObject = JObject.Parse(responceString);

            this.Postcode  = postcode;
            this.Longitude = (double)responseObject.SelectToken("results[0].geometry.location.lng");
            this.Latitude  = (double)responseObject.SelectToken("results[0].geometry.location.lat");
        }