/// <summary> /// Gets the geolocation lookup of the current <seealso cref="Location"/> object. /// </summary> /// <param name="config">Config that includes the Google Maps key and OSM Nominatim endpoint</param> /// <returns>Returns a <seealso cref="Location"/> object containing the address</returns> public Location GetAddress(WhConfig config) { var key = (Latitude, Longitude); // Check if cache already contains lat/lon tuple key, if so return it. if (_cache.ContainsKey(key)) { return(_cache[key]); } // Check if we want any reverse geocoding address Location location = null; if (!string.IsNullOrEmpty(config.GoogleMapsKey)) { location = GetGoogleAddress(City, Latitude, Longitude, config.GoogleMapsKey); } if (!string.IsNullOrEmpty(config.NominatimEndpoint)) { location = GetNominatimAddress(City, Latitude, Longitude, config.NominatimEndpoint, config.NominatimSchema); } // Check if lat/lon tuple key has not been cached already, if not add it. if (!_cache.ContainsKey(key)) { _cache.Add(key, location); } return(location); }
private LocationInfo AddLocationInfo(string locationName, string locationIdentifier, Offset utcOffset, Guid?uniqueId = null) { const long dummyId = 0; var locationInfo = InternalConstructor <LocationInfo> .Invoke( locationName, locationIdentifier, dummyId, uniqueId ?? Guid.Empty, utcOffset.ToTimeSpan().TotalHours); if (LocationCache.SingleOrDefault(l => l.LocationIdentifier == locationInfo.LocationIdentifier) == null) { LocationCache.Add(locationInfo); } return(locationInfo); }