Exemple #1
0
    /// <summary>
    /// Returns a list of 3 word addresses based on user input and other parameters.
    /// </summary>
    /// <param name="key">A valid API key</param>
    /// <param name="addr">The full or partial 3 word address to obtain suggestions for. At minimum this must be the first two complete words plus at least one character from the third word.</param>
    /// <param name="multilingual">AutoSuggest is provided via 2 variant resources; single language and multilingual.</param>
    /// <param name="lang">For single language the lang parameter is required; for multilingual, the lang parameter is optional. If specified, this parameter must be a supported 3 word address language as an ISO 639-1 2 letter code.</param>
    /// <param name="focus">A location, used to refine the results. If specified, the results will be weighted to give preference to those near the specified location in addition to considering similarity to the addr string. If omitted the default behaviour is to weight results for similarity to the addr string only.</param>
    /// <param name="clip">Restricts results to those within a geographical area.</param>
    /// <param name="count">The number of AutoSuggest results to return. A maximum of 100 results can be specified, if a number greater than this is requested, this will be truncated to the maximum. The default is 3.</param>
    /// <param name="display">Display type.</param>
    /// <returns>Query instance.</returns>
    public static OnlineMapsWhat3Words AutoSuggest(string key, string addr, bool multilingual = false, string lang = "en", OnlineMapsVector2d?focus = null, Clip clip = null, int?count = null, Display display = Display.full)
    {
        if (string.IsNullOrEmpty(key))
        {
            key = OnlineMapsKeyManager.What3Words();
        }

        StringBuilder url = new StringBuilder(endpoint).Append("autosuggest");

        if (multilingual)
        {
            url.Append("-ml");
        }
        url.Append("?format=json&key=").Append(key);
        url.Append("&addr=").Append(addr);
        if (!string.IsNullOrEmpty(lang))
        {
            url.Append("&lang=").Append(lang);
        }
        if (focus.HasValue)
        {
            url.Append("&focus=").Append(focus.Value.y.ToString(OnlineMapsUtils.numberFormat)).Append(",")
            .Append(focus.Value.x.ToString(OnlineMapsUtils.numberFormat));
        }
        if (clip != null)
        {
            clip.AppendURL(url);
        }
        if (count.HasValue)
        {
            url.Append("&count=").Append(count.Value);
        }
        if (display != Display.full)
        {
            if (display == Display.minimal)
            {
                throw new Exception("AutoSuggest does not support Display.minimal.");
            }
            url.Append("&display=").Append(display);
        }
        return(new OnlineMapsWhat3Words(url));
    }