public void CanGeocodeAddress()
 {
     asyncGeocoder.GeocodeAsync("1600 pennsylvania ave washington dc").ContinueWith(task =>
     {
         Address[] addresses = task.Result.ToArray();
         addresses[0].AssertWhiteHouse();
     });
 }
Esempio n. 2
0
        public async Task <IEnumerable <MapMarker> > GetMarkers(IEnumerable <EstablishmentModel> establishments)
        {
            IList <MapMarker> markers = new List <MapMarker>();

            foreach (var establishment in establishments)
            {
                var inputAddress = establishment.Address.GetFormatted();
                var addresses    = await _geocoder.GeocodeAsync(inputAddress);

                var result = addresses.First();

                var marker = new MapMarker
                {
                    Latitude         = result.Coordinates.Latitude,
                    Longitude        = result.Coordinates.Longitude,
                    ShortCode        = establishment.ShortCode,
                    Name             = establishment.Name,
                    Description      = establishment.Description,
                    Type             = establishment.Type,
                    Logo             = establishment.Logo,
                    FormattedAddress = inputAddress,
                    BusinessHours    = establishment.BusinessHours,
                };

                markers.Add(marker);
            }

            return(markers);
        }
Esempio n. 3
0
        private Address GetAddressFromString(string city)
        {
            var addresses = _geocoder.GeocodeAsync(city).Result;
            var address   = addresses.First();

            return(address);
        }
Esempio n. 4
0
        public Location EncodeGeocodeAsync(string RegionGeoJson)
        {
            var address = _geocoder.GeocodeAsync(RegionGeoJson);

            address.Wait();
            return(address.Result.First().Coordinates);
        }
        public async Task <GeoPoint> UpdateLatLong(IGeocoder geo)
        {
            var geoPoint = await geo.GeocodeAsync(
                $"{Address1}, {Address2}, {City} {State} {Postal} {Country}"
                );

            Latitude  = geoPoint?.Latitude;
            Longitude = geoPoint?.Longitude;

            return(geoPoint);
        }
Esempio n. 6
0
        public Tuple <double, double> GetLatLong(string adress)
        {
            IEnumerable <Address> addresses = geocoder.GeocodeAsync(adress + "Buenos Aires Argentina").Result;

            if (addresses.Count() == 0)
            {
                return(null);
            }
            var tuple = new Tuple <double, double>(addresses.First().Coordinates.Latitude, addresses.First().Coordinates.Longitude);

            return(tuple);
        }
Esempio n. 7
0
        public async Task <Coordinates> GetCoordinates(string address, string city, string state, string zip)
        {
            IGeocoder             geocoder  = Geocoder.Instance.IGeo;
            IEnumerable <Address> addresses = await geocoder.GeocodeAsync(string.Format("{0} {1}, {2} {3}", address, city, state, zip));

            Coordinates c = new Coordinates
            {
                Longitude = addresses.First().Coordinates.Longitude,
                Latitude  = addresses.First().Coordinates.Latitude
            };

            return(c);
        }
Esempio n. 8
0
        public async Task <LocationFinderResult> GetLocationFromStringAsync(string locationText)
        {
            try
            {
                locationText = InvokeLocationOverrideOrReturnOriginal(locationText);
                if (!locationText.EndsWith(",scotland", StringComparison.InvariantCultureIgnoreCase))
                {
                    locationText = locationText + ",scotland"; //hack to restrict returned locations to scotland
                }
                IEnumerable <BingAddress> addresses = await _geoCoder.GeocodeAsync(locationText) as IEnumerable <BingAddress>;

                if (addresses == null || !addresses.Any())
                {
                    return(null);
                }

                var matchedLocation = addresses.Where(x => x.Type == EntityType.PopulatedPlace &&
                                                      x.Confidence <= ConfidenceLevel.Medium &&
                                                      x.CountryRegion == "United Kingdom" &&
                                                      x.AdminDistrict == "Scotland"
                                                      ).FirstOrDefault();
                if (matchedLocation == null)
                {
                    return(null);
                }

                Logging.Debug("Formatted: " + addresses.First().FormattedAddress);
                Logging.Debug("Coordinates: " + addresses.First().Coordinates.Latitude + ", " + addresses.First().Coordinates.Longitude);
                return(new LocationFinderResult
                {
                    AdminDistrict2 = GetAreaName(matchedLocation.AdminDistrict2),
                    Coordinates = new Coordinates
                    {
                        Latitude = matchedLocation.Coordinates.Latitude,
                        Longitude = matchedLocation.Coordinates.Longitude
                    },
                    Confidence = matchedLocation.Confidence == ConfidenceLevel.High ? LocationConfidence.HIGH : LocationConfidence.MEDIUM
                });
            }
            catch (Exception e)
            {
                Logging.Error($"Exception caught in GetLocationFromStringAsync method, message: {e.Message}");
                Logging.Debug(JsonConvert.SerializeObject(e, Formatting.Indented,
                                                          new JsonSerializerSettings()
                {
                    ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore
                }));
                return(null);
            }
        }
Esempio n. 9
0
        public async System.Threading.Tasks.Task <ActionResult> ViewCityDetails(int id)
        {
            Cities                city      = db.Cities.Find(id);
            IGeocoder             geocoder  = Geocoder.Instance.IGeo;
            IEnumerable <Address> addresses = await geocoder.GeocodeAsync(city.CityName + ", " + city.State);

            if (city.Coordinates == null)
            {
                city.Coordinates = new Coordinates();
            }
            city.Coordinates.Longitude = addresses.FirstOrDefault().Coordinates.Longitude;
            city.Coordinates.Latitude  = addresses.FirstOrDefault().Coordinates.Latitude;
            return(View(city));
        }
Esempio n. 10
0
        public static IEnumerable <Address> Geocode(this IGeocoder geocoder, string address)
        {
            if (string.IsNullOrEmpty(address))
            {
                throw new System.ArgumentNullException("address");
            }

            if (Geocoding.Location.TryParse(address, out Geocoding.Location location))
            {
                return(ReverseGeocode(geocoder, location));
            }
            else
            {
                IEnumerable <Address> addresses = Task.Factory.StartNew(() => geocoder.GeocodeAsync(address)).Unwrap().GetAwaiter().GetResult();
                return(addresses);
            }
        }
Esempio n. 11
0
 public async Task <IEnumerable <LocationDto> > GetAdresses(string data)
 {
     try
     {
         addresses = await geocoder.GeocodeAsync(data);
     }
     catch (Exception ex)
     {
         var errorLocations = new List <LocationDto>()
         {
             {
                 new LocationDto()
                 {
                     Error = ex.Message
                 }
             }
         };
         return(errorLocations);
     }
     return(GetLocations(addresses));
 }
Esempio n. 12
0
 public virtual async Task CanGeocodeAddress(string address)
 {
     Address[] addresses = (await geocoder.GeocodeAsync(address)).ToArray();
     addresses[0].AssertWhiteHouse();
 }
Esempio n. 13
0
        public static async Task <Address> GetGeocodedAddress(string inputAddress)
        {
            IEnumerable <Address> addresses = await geocoder.GeocodeAsync(inputAddress);

            return(addresses.First());
        }
Esempio n. 14
0
        public async Task CanGeocodeAddress()
        {
            var addresses = await asyncGeocoder.GeocodeAsync("1600 pennsylvania ave washington dc");

            addresses.First().AssertWhiteHouse();
        }
Esempio n. 15
0
        public async Task Test2()
        {
            var address = await geocoder.GeocodeAsync("United States");

            Assert.NotNull(address);
        }