コード例 #1
0
 //https://github.com/chadly/Geocoding.net/issues/8
 public void CanReverseGeocodeIssue8()
 {
     BingAddress[] addresses = geoCoder.ReverseGeocode(38.8976777, -77.036517).ToArray();
     Assert.NotEmpty(addresses);
 }
コード例 #2
0
        public string GetAddressFromLatLong(double lat, double lon)
        {
            Func <string> getAddressFromCords = delegate()
            {
                IGeocoder googleGeoCoder = new GoogleGeocoder()
                {
                    ApiKey = Config.MappingConfig.GoogleMapsApiKey
                };
                IGeocoder bingGeoCoder = new BingMapsGeocoder(Config.MappingConfig.BingMapsApiKey);

                string address = null;

                try
                {
                    var addresses = googleGeoCoder.ReverseGeocode(lat, lon);

                    if (addresses != null && addresses.Any())
                    {
                        address = addresses.First().FormattedAddress;
                    }
                }
                catch
                {
                }

                if (string.IsNullOrWhiteSpace(address))
                {
                    try
                    {
                        var addressGeo = GetAddressFromLatLonLocationIQ(lat.ToString(), lon.ToString());

                        if (!String.IsNullOrWhiteSpace(addressGeo))
                        {
                            address = addressGeo;
                        }
                    }
                    catch
                    {
                    }
                }

                if (string.IsNullOrWhiteSpace(address))
                {
                    try
                    {
                        var addresses = bingGeoCoder.ReverseGeocode(lat, lon);

                        if (addresses != null && addresses.Count() > 0)
                        {
                            address = addresses.First().FormattedAddress;
                        }
                    }
                    catch
                    {
                    }
                }
                return(address);
            };

            return(_cacheProvider.Retrieve <string>(string.Format(ReverseCacheKey, string.Format("{0} {1}", lat, lon).GetHashCode()), getAddressFromCords, CacheLength));
        }