コード例 #1
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="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
        /// <returns>The geocode response.</returns>
        public async Task <GeocodeResponse> GeocodeComponentFilter(ComponentFilter filter, string region = null)
        {
            var request  = BuildRequest(filter, region);
            var response = await DoRequestAsync(request);

            return(JsonConvert.DeserializeObject <GeocodeResponse>(response));
        }
コード例 #2
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildUrl(string address, string region, ComponentFilter filter)
        {
            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ArgumentNullException("address");
            }
            var addressPortion = BuildAddressPortion(address, region, filter);
            var authPortion    = BuildAuthPortion(addressPortion);

            return(string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion));
        }
コード例 #3
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildUrl(ComponentFilter filter, string region)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            var addressPortion = BuildAddressPortion(filter, region);
            var authPortion    = BuildAuthPortion(addressPortion);

            return(string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion));
        }
コード例 #4
0
        private HttpWebRequest BuildRequest(ComponentFilter filter, string region)
        {
            if (filter == null)
            {
                throw new ArgumentNullException("filter");
            }
            var addressPortion = BuildAddressPortion(filter, region);
            var authPortion    = BuildAuthPortion(addressPortion);

            return(_proxyProvider.CreateRequest(string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion)));
        }
コード例 #5
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildAddressPortion(ComponentFilter filter, string region)
        {
            var filterString = filter.ToUrlParameters();

            if (string.IsNullOrWhiteSpace(filterString))
            {
                throw new ArgumentException("Component filter doesn't contain any component", "filter");
            }
            var addressPortion = string.Format("components={0}", filterString);

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

            return(addressPortion);
        }
コード例 #6
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildAddressPortion(string address, string region, ComponentFilter filter)
        {
            var addressPortion = string.Format("address={0}", Uri.EscapeDataString(address));

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

            if (filter != null)
            {
                var filterString = filter.ToUrlParameters();
                if (!string.IsNullOrWhiteSpace(filterString))
                {
                    addressPortion += string.Format("&components={0}", filterString);
                }
            }

            return(addressPortion);
        }
コード例 #7
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="address">The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</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="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <returns>The geocode response.</returns>
        public async Task <GeocodeResponse> GeocodeAddress(string address, string region = null, ComponentFilter filter = null, string language = null)
        {
            var request  = BuildRequest(address, region, language, filter);
            var response = await DoRequestAsync(request);

            return(JsonConvert.DeserializeObject <GeocodeResponse>(response));
        }
コード例 #8
0
        private HttpWebRequest BuildRequest(string address, string region, string language, ComponentFilter filter)
        {
            if (string.IsNullOrWhiteSpace(address))
            {
                throw new ArgumentNullException("address");
            }
            var addressPortion = BuildAddressPortion(address, region, language, filter);
            var authPortion    = BuildAuthPortion(addressPortion);

            return(_proxyProvider.CreateRequest(string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion)));
        }
コード例 #9
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
 private string BuildUrl(string address, string region, ComponentFilter filter)
 {
     if (string.IsNullOrWhiteSpace(address)) throw new ArgumentNullException("address");
     var addressPortion = BuildAddressPortion(address, region, filter);
     var authPortion = BuildAuthPortion(addressPortion);
     return string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion);
 }
コード例 #10
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="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
        /// <returns>The geocode response.</returns>
        public async Task <string> GeocodeComponentFilterJson(ComponentFilter filter, string region = null)
        {
            var request = BuildRequest(filter, region);

            return(await DoRequestAsync(request));
        }
コード例 #11
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="address">The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</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="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <returns>The geocode response.</returns>
        public async Task <string> GeocodeAddressJson(string address, string region = null, ComponentFilter filter = null, string language = null)
        {
            var request = BuildRequest(address, region, language, filter);

            return(await DoRequestAsync(request));
        }
コード例 #12
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
 /// <summary>
 /// Calls Google's geocode API with the specified address and optional region.
 /// https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
 /// </summary>
 /// <param name="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
 /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
 /// <returns>The geocode response.</returns>
 public async Task<GeocodeResponse> GeocodeComponentFilter(ComponentFilter filter, string region = null)
 {
     var url = BuildUrl(filter, region);
     return await DoRequestAsync(url);
 }
コード例 #13
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
 /// <summary>
 /// Calls Google's geocode API with the specified address and optional region.
 /// https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
 /// </summary>
 /// <param name="address">The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.</param>
 /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
 /// <param name="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
 /// <returns>The geocode response.</returns>
 public async Task<GeocodeResponse> GeocodeAddress(string address, string region = null, ComponentFilter filter = null)
 {
     var url = BuildUrl(address, region, filter);
     return await DoRequestAsync(url);
 }
コード例 #14
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildAddressPortion(string address, string region, ComponentFilter filter)
        {
            var addressPortion = string.Format("address={0}", Uri.EscapeDataString(address));
            if (!string.IsNullOrWhiteSpace(region))
            {
                addressPortion += string.Format("&region={0}", Uri.EscapeDataString(region));
            }

            if (filter != null)
            {
                var filterString = filter.ToUrlParameters();
                if (!string.IsNullOrWhiteSpace(filterString))
                {
                    addressPortion += string.Format("&components={0}", filterString);
                }
            }

            return addressPortion;
        }
コード例 #15
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        private string BuildAddressPortion(ComponentFilter filter, string region)
        {
            var filterString = filter.ToUrlParameters();
            if(string.IsNullOrWhiteSpace(filterString))
                throw new ArgumentException("Component filter doesn't contain any component", "filter");
            var addressPortion = string.Format("components={0}", filterString);
            if (!string.IsNullOrWhiteSpace(region))
            {
                addressPortion += string.Format("&region={0}", Uri.EscapeDataString(region));
            }

            return addressPortion;
        }
コード例 #16
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        /// <summary>
        /// Calls Google's geocode API with the specified address and optional region.
        /// https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
        /// </summary>
        /// <param name="address">The street address that you want to geocode, in the format used by the national postal service of the country concerned. Additional address elements such as business names and unit, suite or floor numbers should be avoided.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
        /// <param name="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <returns>The geocode response.</returns>
        public async Task <GeocodeResponse> GeocodeAddress(string address, string region = null, ComponentFilter filter = null)
        {
            var url = BuildUrl(address, region, filter);

            return(await DoRequestAsync(url));
        }
コード例 #17
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
        /// <summary>
        /// Calls Google's geocode API with the specified address and optional region.
        /// https://developers.google.com/maps/documentation/geocoding/#GeocodingRequests
        /// </summary>
        /// <param name="filter">A component filter for which you wish to obtain a geocode. The component filter swill fully restrict the results from the geocoder. Only the results that match all the filters will be returned. Each address component can only be specified either in the address parameter or as a component filter, but not both. Doing so may result in ZERO_RESULTS.</param>
        /// <param name="region">The region code, specified as a ccTLD ("top-level domain") two-character value. This parameter will only influence, not fully restrict, results from the geocoder.</param>
        /// <returns>The geocode response.</returns>
        public async Task <GeocodeResponse> GeocodeComponentFilter(ComponentFilter filter, string region = null)
        {
            var url = BuildUrl(filter, region);

            return(await DoRequestAsync(url));
        }
コード例 #18
0
ファイル: GeocodeClient.cs プロジェクト: huangcd/GeocodeSharp
 private string BuildUrl(ComponentFilter filter, string region)
 {
     if (filter == null)
         throw new ArgumentNullException("filter");
     var addressPortion = BuildAddressPortion(filter, region);
     var authPortion = BuildAuthPortion(addressPortion);
     return string.Format("{0}{1}{2}{3}", _domain, _apiPath, addressPortion, authPortion);
 }