Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/Geo.Bing/Models/Parameters/BaseParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,23 @@ public class BaseParameters : IAdditionalParameters
/// </summary>
public CultureInfo Culture { get; set; }

/// <summary>
/// Gets or sets the user's current location to help determine better results.
/// Format: latitude,longitude (e.g., "47.608,-122.337"). Optional.
/// </summary>
public string UserLocation { get; set; }

/// <summary>
/// Gets or sets the IP address of the user's device to help determine better results. Optional.
/// </summary>
public string UserIp { get; set; }

/// <summary>
/// Gets or sets the map area currently shown to the user to help determine better results.
/// Format: southLatitude,westLongitude,northLatitude,eastLongitude. Optional.
/// </summary>
public string UserMapView { get; set; }

/// <inheritdoc/>
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
}
Expand Down
6 changes: 6 additions & 0 deletions src/Geo.Bing/Models/Parameters/ResultParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@ public class ResultParameters : BaseParameters
/// If the value is 0, the default value will be used.
/// </summary>
public int MaximumResults { get; set; } = 5;

/// <summary>
/// Gets or sets a value indicating whether to restrict results to the country/region and adminDistrict specified.
/// When true, results outside the specified countryRegion and adminDistrict will not be returned. Optional.
/// </summary>
public bool StrictMatch { get; set; } = false;
}
}
6 changes: 6 additions & 0 deletions src/Geo.Bing/Models/Parameters/ReverseGeocodingParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ public class ReverseGeocodingParameters : BaseParameters, IKeyParameters
/// </summary>
public bool IncludeCountryRegion { get; set; }

/// <summary>
/// Gets or sets a value indicating whether AdminDistrict names are returned in expanded form.
/// When true, returns "Washington" instead of "WA". Defaults to false. Optional.
/// </summary>
public bool VerbosePlaceNames { get; set; } = false;

/// <inheritdoc/>
public string Key { get; set; }
}
Expand Down
25 changes: 25 additions & 0 deletions src/Geo.Bing/Services/BingGeocoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)
_logger.BingDebug(Resources.Services.BingGeocoding.Do_Not_Include_Entity_Types);
}

if (parameters.VerbosePlaceNames)
{
query = query.Add("verboseplacenames", "true");
}

BuildBaseQuery(parameters, ref query);

AddBingKey(parameters, ref query);
Expand Down Expand Up @@ -297,6 +302,11 @@ internal void BuildLimitedResultQuery(ResultParameters parameters, ref QueryStri
_logger.BingWarning(Resources.Services.BingGeocoding.Invalid_Maximum_Results);
}

if (parameters.StrictMatch)
{
query = query.Add("strictMatch", "1");
}

BuildBaseQuery(parameters, ref query);
}

Expand Down Expand Up @@ -344,6 +354,21 @@ internal void BuildBaseQuery(BaseParameters parameters, ref QueryString query)
{
_logger.BingDebug(Resources.Services.BingGeocoding.Invalid_Culture);
}

if (!string.IsNullOrWhiteSpace(parameters.UserLocation))
{
query = query.Add("userLocation", parameters.UserLocation);
}

if (!string.IsNullOrWhiteSpace(parameters.UserIp))
{
query = query.Add("userIp", parameters.UserIp);
}

if (!string.IsNullOrWhiteSpace(parameters.UserMapView))
{
query = query.Add("usermapView", parameters.UserMapView);
}
}

/// <summary>
Expand Down
12 changes: 12 additions & 0 deletions src/Geo.Google/Models/Parameters/DetailsParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,18 @@ public class DetailsParameters : BaseParameters, IKeyParameters
/// </summary>
public string SessionToken { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to disable translation of reviews.
/// When true, the language code is included in the response along with the original-language review text. Optional.
/// </summary>
public bool? ReviewsNoTranslations { get; set; }

/// <summary>
/// Gets or sets the sort order for reviews.
/// Accepted values: most_relevant, newest. Optional.
/// </summary>
public string ReviewsSort { get; set; }

/// <inheritdoc/>
public string Key { get; set; }
}
Expand Down
7 changes: 7 additions & 0 deletions src/Geo.Google/Models/Parameters/GeocodingParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

namespace Geo.Google.Models.Parameters
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;

Expand Down Expand Up @@ -36,6 +37,12 @@ public class GeocodingParameters : BaseParameters, IKeyParameters
/// </summary>
public RegionInfo Region { get; set; }

/// <summary>
/// Gets the list of extra computations to apply to the geocoding request.
/// Supported values: ADDRESS_DESCRIPTORS, BUILDING_AND_ENTRANCES. Optional.
/// </summary>
public IList<string> ExtraComputations { get; } = new List<string>();

/// <inheritdoc/>
public string Key { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ public class PlacesAutocompleteParameters : QueryAutocompleteParameters
/// This is a restriction, rather than a bias, meaning that results outside this region will not be returned even if they match the user input.
/// </summary>
public bool StrictBounds { get; set; } = false;

/// <summary>
/// Gets or sets a hard restriction on the area in which results are returned.
/// Results outside this region will not be returned. Accepts a <see cref="Circle"/> or <see cref="Boundaries"/> value. Optional.
/// </summary>
public object LocationRestriction { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace Geo.Google.Models.Parameters
{
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using Geo.Google.Enums;

/// <summary>
Expand Down Expand Up @@ -39,6 +40,12 @@ public class ReverseGeocodingParameters : BaseParameters, IKeyParameters
/// </summary>
public IEnumerable<LocationType> LocationTypes { get; set; }

/// <summary>
/// Gets the list of extra computations to apply to the reverse geocoding request.
/// Supported values: ADDRESS_DESCRIPTORS, BUILDING_AND_ENTRANCES. Optional.
/// </summary>
public IList<string> ExtraComputations { get; } = new List<string>();

/// <inheritdoc/>
public string Key { get; set; }
}
Expand Down
50 changes: 50 additions & 0 deletions src/Geo.Google/Services/GoogleGeocoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,17 @@ internal Uri BuildGeocodingRequest(GeocodingParameters parameters)
_logger.GoogleDebug(Resources.Services.GoogleGeocoding.Invalid_Region);
}

if (parameters.ExtraComputations != null)
{
foreach (var computation in parameters.ExtraComputations)
{
if (!string.IsNullOrWhiteSpace(computation))
{
query = query.Add("extra_computations", computation);
}
}
}

AddBaseParameters(parameters, ref query);

AddGoogleKey(parameters, ref query);
Expand Down Expand Up @@ -301,6 +312,17 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)
_logger.GoogleDebug(Resources.Services.GoogleGeocoding.Invalid_Location_Types);
}

if (parameters.ExtraComputations != null)
{
foreach (var computation in parameters.ExtraComputations)
{
if (!string.IsNullOrWhiteSpace(computation))
{
query = query.Add("extra_computations", computation);
}
}
}

AddBaseParameters(parameters, ref query);

AddGoogleKey(parameters, ref query);
Expand Down Expand Up @@ -533,6 +555,18 @@ internal Uri BuildDetailsRequest(DetailsParameters parameters)
_logger.GoogleDebug(Resources.Services.GoogleGeocoding.Invalid_Fields);
}

if (parameters.ReviewsNoTranslations.HasValue)
{
#pragma warning disable CA1308 // Normalize strings to uppercase
query = query.Add("reviews_no_translations", parameters.ReviewsNoTranslations.Value.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
#pragma warning restore CA1308 // Normalize strings to uppercase
}

if (!string.IsNullOrWhiteSpace(parameters.ReviewsSort))
{
query = query.Add("reviews_sort", parameters.ReviewsSort);
}

AddBaseParameters(parameters, ref query);

AddGoogleKey(parameters, ref query);
Expand Down Expand Up @@ -600,6 +634,22 @@ internal Uri BuildPlaceAutocompleteRequest(PlacesAutocompleteParameters paramete
query = query.Add("strictbounds", parameters.StrictBounds.ToString(CultureInfo.InvariantCulture).ToLowerInvariant());
#pragma warning restore CA1308 // Normalize strings to uppercase

if (parameters.LocationRestriction != null)
{
switch (parameters.LocationRestriction)
{
case Circle circle:
query = query.Add("locationrestriction", $"circle:{circle}");
break;
case Boundaries boundary:
query = query.Add("locationrestriction", $"rectangle:{boundary}");
break;
default:
_logger.GoogleWarning(Resources.Services.GoogleGeocoding.Invalid_Location_Bias_Type);
break;
}
}

AddAutocompleteParameters(parameters, ref query);

AddGoogleKey(parameters, ref query);
Expand Down
18 changes: 18 additions & 0 deletions src/Geo.MapBox/Abstractions/IMapBoxGeocoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,23 @@ public interface IMapBoxGeocoding
/// <returns>A <see cref="Response{Coordinate}"/> with the response from MapBox.</returns>
/// <exception cref="GeoNETException">Thrown for multiple different reasons. Check the inner exception for more information.</exception>
Task<Response<Coordinate>> ReverseGeocodingAsync(ReverseGeocodingParameters parameters, CancellationToken cancellationToken = default);

/// <summary>
/// Calls the MapBox Geocoding API v6 (forward) and returns the results.
/// </summary>
/// <param name="parameters">A <see cref="GeocodingV6Parameters"/> with the parameters of the request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the request.</param>
/// <returns>A <see cref="Response{T}"/> with a <see cref="List{T}"/> of <see cref="string"/> with the response from MapBox.</returns>
/// <exception cref="GeoNETException">Thrown for multiple different reasons. Check the inner exception for more information.</exception>
Task<Response<List<string>>> GeocodingV6Async(GeocodingV6Parameters parameters, CancellationToken cancellationToken = default);

/// <summary>
/// Calls the MapBox Geocoding API v6 (reverse) and returns the results.
/// </summary>
/// <param name="parameters">A <see cref="ReverseGeocodingV6Parameters"/> with the parameters of the request.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> used to cancel the request.</param>
/// <returns>A <see cref="Response{Coordinate}"/> with the response from MapBox.</returns>
/// <exception cref="GeoNETException">Thrown for multiple different reasons. Check the inner exception for more information.</exception>
Task<Response<Coordinate>> ReverseGeocodingV6Async(ReverseGeocodingV6Parameters parameters, CancellationToken cancellationToken = default);
}
}
86 changes: 86 additions & 0 deletions src/Geo.MapBox/Models/Parameters/GeocodingV6Parameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// <copyright file="GeocodingV6Parameters.cs" company="Geo.NET">
// Copyright (c) Geo.NET.
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information.
// </copyright>

namespace Geo.MapBox.Models.Parameters
{
using System.Collections.Generic;
using System.Globalization;
using Geo.MapBox.Enums;
using Geo.MapBox.Models;

/// <summary>
/// The parameters possible to use during a Mapbox Geocoding API v6 forward geocoding request.
/// </summary>
public class GeocodingV6Parameters : IKeyParameters, IAdditionalParameters
{
/// <summary>
/// Gets or sets the search text to geocode.
/// </summary>
public string Query { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to store results permanently.
/// Must be true when using the Permanent endpoint (requires an enterprise plan). Default is false. Optional.
/// </summary>
public bool Permanent { get; set; } = false;

/// <summary>
/// Gets or sets a value indicating whether to enable autocomplete suggestions. Optional.
/// </summary>
public bool? Autocomplete { get; set; }

/// <summary>
/// Gets or sets a bounding box to limit results. Optional.
/// </summary>
public BoundingBox BoundingBox { get; set; }

/// <summary>
/// Gets the list of countries to limit the request to. Optional.
/// </summary>
public IList<RegionInfo> Countries { get; } = new List<RegionInfo>();

/// <summary>
/// Gets or sets the response format. Accepted values: geojson, v5. Defaults to geojson. Optional.
/// </summary>
public string Format { get; set; }

/// <summary>
/// Gets the list of languages of the text supplied in responses. Optional.
/// </summary>
public IList<CultureInfo> Languages { get; } = new List<CultureInfo>();

/// <summary>
/// Gets or sets the maximum number of results to return. Default is 5. Optional.
/// </summary>
public uint? Limit { get; set; }

/// <summary>
/// Gets or sets a location to bias results toward. Format: longitude,latitude or "ip". Optional.
/// </summary>
public string Proximity { get; set; }

/// <summary>
/// Gets a list used to filter results to include only a subset of available feature types. Optional.
/// </summary>
public IList<FeatureType> Types { get; } = new List<FeatureType>();

/// <summary>
/// Gets or sets the worldview to use.
/// Available values: ar, cn, in, jp, ma, rs, ru, tr, us. Defaults to us. Optional.
/// </summary>
public string Worldview { get; set; }

/// <summary>
/// Gets or sets a value indicating whether to include building entrance data (beta feature). Optional.
/// </summary>
public bool? Entrances { get; set; }

/// <inheritdoc/>
public string Key { get; set; }

/// <inheritdoc/>
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
}
}
Loading
Loading