Beispiel #1
0
        /// <summary>
        /// Create a web request to query the Bing Maps REST API and return the Bing Location Response.
        /// </summary>
        /// <param name="query">A string that contains information about a location, such as an address or landmark name.</param>
        /// <returns>BingLocationResponse</returns>
        public BingLocationResponse GetGeocodeLocationByQuery(string query)
        {
            BingLocationResponse result = null;

            var request = WebRequest.Create(string.Format("{0}?Key={1}&query={2}&userLocation={3}&inclnb={4}", BingMapRestUrl, BingMapKey, query, UserLocation, IncludeNeighborhood ?? 0)) as HttpWebRequest;


            if (request != null)
            {
                using (var response = (HttpWebResponse)request.GetResponse())
                {
                    result = GetResult(response);
                }
            }


            return(result);
        }
Beispiel #2
0
        private static BingLocationResponse GetResult(HttpWebResponse response)
        {
            BingLocationResponse result = null;

            if (response != null && response.StatusCode == HttpStatusCode.OK)
            {
                using (var stream = response.GetResponseStream())
                {
                    var serialiser = new DataContractJsonSerializer(typeof(BingLocationResponse));

                    if (stream != null)
                    {
                        result = serialiser.ReadObject(stream) as BingLocationResponse;
                    }
                }
            }

            return(result);
        }