Ejemplo n.º 1
0
        /// <summary>
        /// Returns Place predictions given a textual search string and optional geographic bounds.
        /// </summary>
        /// <param name="input">The text string on which to search</param>
        /// <param name="offset">The position, in the input term, of the last character that
        /// the service uses to match predictions.For example, if the input is 'Google' and
        /// the offset is 3, the service will match on 'Goo'.</param>
        /// <param name="location">The latitude/longitude value for which you wish to obtain
        /// the closest, human-readable address.</param>
        /// <param name="radius">The distance (in meters) within which to return place results.</param>
        /// <param name="language">The language code, indicating in which language the results should be returned, if possible</param>
        /// <param name="types">The types of place results to return</param>
        /// <param name="components">A grouping of places to which you would like to restrict your results.</param>
        /// <returns>Result</returns>
        public PlaceAutocompleteResponse AutoComplete(string input, int?offset = null, IGeoCoordinatesLocation location = null,
                                                      int?radius = null, string language = null, IEnumerable <string> types = null,
                                                      ComponentsFilter components = null)
        {
            // Assign query params
            var queryParams = new QueryParams
            {
                ["input"] = input
            };

            // Offset
            if (offset.HasValue)
            {
                queryParams["offset"] = Converter.Number(offset.Value);
            }

            // Location
            if (location != null)
            {
                queryParams["location"] = Converter.Location(location);
            }

            // Radius
            if (radius.HasValue)
            {
                queryParams["radius"] = Converter.Number(radius.Value);
            }

            // Language
            if (language != null)
            {
                queryParams["language"] = language;
            }

            // Types
            if (types != null)
            {
                queryParams["types"] = Converter.JoinList(types);
            }

            // Components
            if (components != null)
            {
                queryParams["components"] = Converter.Components(components);
            }

            // Get API response result
            var response = Client.APIGet <PlaceAutocompleteResponse>("/maps/api/place/autocomplete/json", queryParams);

            // Return it
            return(response);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Converts a dict of components to the format expected by the Google Maps
        /// server.
        ///
        /// For example:
        /// c = {"country": "US", "postal_code": "94043"}
        /// convert.components(c)
        /// # 'country:US|postal_code:94043'
        ///
        /// </summary>
        /// <param name="components">The components filter</param>
        /// <returns>Result string</returns>
        public static string Components(ComponentsFilter components)
        {
            return(string.Join("|",
                               components.AllKeys.OrderBy(x => x).Select(y => $"{y}:{components[y]}")));

            /*
             *
             * if isinstance(arg, dict):
             *  arg = sorted(["%s:%s" % (k, arg[k]) for k in arg])
             *  return "|".join(arg)
             *
             */
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Geocoding is the process of converting addresses
        /// (like "1600 Amphitheatre Parkway, Mountain View, CA") into geographic
        /// coordinates(like latitude 37.423021 and longitude -122.083739), which you
        /// can use to place markers or position the map.
        /// </summary>
        /// <param name="address">
        /// The address to geocode.
        /// </param>
        /// <param name="components">
        /// A component filter for which you wish to obtain a
        /// geocode, for example: {"administrative_area": "TX","country": "US"}
        /// </param>
        /// <param name="bounds">
        /// The bounding box of the viewport within which to bias geocode
        /// results more prominently.
        /// </param>
        /// <param name="region">
        /// The region code, specified as a ccTLD ("top-level domain") two-character value.
        /// </param>
        /// <param name="language">
        /// The language in which to return results.
        /// </param>
        /// <returns>Geocoding results</returns>
        public GeocodeResponse Geocode(string address             = null, ComponentsFilter components = null,
                                       ViewportBoundingBox bounds = null, string region               = null, string language = null)
        {
            // Assign query params
            var queryParams = new QueryParams();

            // Address
            if (address != null)
            {
                queryParams["address"] = address;
            }

            // Components
            if (components != null)
            {
                queryParams["components"] = Converter.Components(components);
            }

            // Bounds
            if (bounds != null)
            {
                queryParams["bounds"] = Converter.Bounds(bounds);
            }

            // Regions
            if (region != null)
            {
                queryParams["region"] = region;
            }

            // Language
            if (language != null)
            {
                queryParams["language"] = language;
            }

            // Get API response result
            var response = Client.APIGet <GeocodeResponse>("/maps/api/geocode/json", queryParams);

            // Return it
            return(response);
        }