public string GetMapUrl(LocationPart part) { if (part == null) { return(null); } if (part.Latitude.HasValue && part.Longitude.HasValue) { return($"https://www.google.com/maps/search/{part.Latitude.Value.ToString("0.000000")},{part.Longitude.Value.ToString("0.000000")}"); } var address = LocationUtilities.AddressForLocation(part).Replace(Environment.NewLine, ","); if (!string.IsNullOrWhiteSpace(address)) { return($"https://www.google.com/maps/search/{address}"); } return(null); }
public LocationPart GeocodeIfRequired(LocationPart part) { if (part == null || string.IsNullOrWhiteSpace(GetApiKey())) { return(part); } // Don't geocode if we already have coordinate values if (part.Latitude.HasValue && part.Longitude.HasValue) { return(part); } var address = LocationUtilities.AddressForLocation(part); var results = Geocode(address); if (!results.Any()) { return(part); } var result = results.First(); part.Latitude = result.Latitude; part.Longitude = result.Longitude; return(part); }