示例#1
0
        private HttpWebRequest BuildRequest(double latitude, double longitude, string language = null, ResultTypeFilter resultTypeFilter = null, LocationTypeFilter locationTypeFilter = null)
        {
            var latLngPortion = BuilLatLngPortion(latitude, longitude, language, resultTypeFilter, locationTypeFilter);
            var authPortion   = BuildAuthPortion(latLngPortion);

            return(_proxyProvider.CreateRequest(string.Format("{0}{1}{2}{3}", _domain, _apiPath, latLngPortion, authPortion)));
        }
示例#2
0
        private string BuilLatLngPortion(double latitude, double longitude, string language, ResultTypeFilter resultTypeFilter = null, LocationTypeFilter locationTypeFilter = null)
        {
            var latLngPortion = string.Format("latlng={0},{1}",
                                              Uri.EscapeDataString(latitude.ToString("0.######", CultureInfo.InvariantCulture)),
                                              Uri.EscapeDataString(longitude.ToString("0.######", CultureInfo.InvariantCulture)));

            if (!string.IsNullOrWhiteSpace(language))
            {
                latLngPortion += string.Format("&language={0}", Uri.EscapeDataString(language));
            }

            if (resultTypeFilter != null)
            {
                latLngPortion += string.Format("&result_type={0}", Uri.EscapeDataString(resultTypeFilter.ToUrlParameters()));
            }

            if (locationTypeFilter != null)
            {
                latLngPortion += string.Format("&location_type={0}", Uri.EscapeDataString(locationTypeFilter.ToUrlParameters()));
            }

            return(latLngPortion);
        }
示例#3
0
        /// <summary>
        /// Calls Google's geocode API with the specified address and optional region.
        /// https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
        /// </summary>
        /// <param name="latitude">The latitude value specifying the location for which you wish to obtain the closest, human-readable address.</param>
        /// <param name="longitude">The longitude value specifying the location for which you wish to obtain the closest, human-readable address.</param>
        /// <param name="language"> The language in which to return results. Address components will all be returned in the same language, which is chosen from the first component. Should names not be available in the preferred language, the closest match will be used.</param>
        /// <param name="locationTypeFilter">The location type filter parameter does not restrict the search to the specified location type(s). Rather, the location type filter acts as a post-search filter: the API fetches all results for the specified latitude and longitude, then discards those results that do not match the specified location type(s).</param>
        /// <param name="resultTypeFilter">The result type filter parameter does not restrict the search to the specified address type(s). Rather, the result type filter acts as a post-search filter: the API fetches all results for the specified latitude and longitude, then discards those results that do not match the specified address type(s).</param>
        /// <returns>The geocode response as JSON.</returns>
        public async Task <string> GeocodeAddressJson(double latitude, double longitude, string language = null, ResultTypeFilter resultTypeFilter = null, LocationTypeFilter locationTypeFilter = null)
        {
            if (_mode == UsageMode.Free && resultTypeFilter != null)
            {
                throw new ArgumentException("You can't use result type filter in free mode, consider running your Geocoding client with API key or client key.");
            }

            if (_mode == UsageMode.Free && locationTypeFilter != null)
            {
                throw new ArgumentException("You can't use location type filter in free mode, consider running your Geocoding client with API key or client key.");
            }

            var request = BuildRequest(latitude, longitude, language, resultTypeFilter, locationTypeFilter);

            return(await DoRequestAsync(request));
        }